主頁 > 移動端開發 > 2020第十一屆11月藍橋杯大賽軟體類B組C/C++省賽題解

2020第十一屆11月藍橋杯大賽軟體類B組C/C++省賽題解

2021-04-13 11:24:57 移動端開發

2020第十一屆11月藍橋杯大賽軟體類B組C/C++省賽目錄

      • 試題 A:門牌制作(結果填空)
      • 試題 B:既約分數(結果填空)
      • 試題 C:蛇形填數(結果填空)
      • 試題 D:跑步鍛煉(結果填空)
      • 試題 E:七段碼(結果填空)
      • 試題 F:成績統計(程式設計)
      • 試題 G:回文日期(結果填空)
      • 試題 H:子串分值和(程式設計)

試題 A:門牌制作(結果填空)

題意
在這里插入圖片描述

做法:直接計算,

代碼

#include<bits/stdc++.h>
using namespace std;
int ct2(int i) {
  int cnt = 0;
  while(i) {
    if(i%10 == 2) ++cnt;
    i /= 10;
  }
  return cnt;
}
int main() {
  int sum = 0;
  for(int i = 1; i <= 2020; ++i) {
    sum += ct2(i);
  }
  cout << sum;
  return 0;
}

答案:624


試題 B:既約分數(結果填空)

題意
在這里插入圖片描述

做法:直接暴力找,

代碼

#include<bits/stdc++.h>
using namespace std;
int main() {
  int cnt = 0;
  for(int i = 1; i <= 2020; ++i) {
    for(int j = 1; j <= 2020; ++j) {
      if(__gcd(i, j) == 1) ++cnt;
    }
  }
  cout << cnt;
  return 0;
}

答案:2481215


試題 C:蛇形填數(結果填空)

題意
在這里插入圖片描述

做法:暴力打出來,
代碼

#include<bits/stdc++.h>
using namespace std;
const int N = 100;
int tu[N][N];
int main() {
  int x = 0, y = 1, cnt = 0;
  for(int i = 1; i <= 60; ++i) {
    if(i&1) ++x;
    else ++y;
    tu[x][y] = ++cnt;
    for(int j = 0; j < i-1; ++j) {
      if(i & 1) {
        tu[x-1][y+1] = ++cnt;
        --x; ++y;
      } else {
        tu[x+1][y-1] = ++cnt;
        ++x; --y;
      }
    }
  }
  for(int i = 1; i <= 20; ++i) {
    for(int j = 1; j <= 20; ++j) {
      cout << tu[i][j] << " ";
    }
    cout << "\n";
  }
  cout << tu[20][20];
  return 0;
}

答案:761

試題 D:跑步鍛煉(結果填空)

題意
在這里插入圖片描述
做法:一天一天模擬,細節比較多,

代碼

#include<bits/stdc++.h>
using namespace std;
const int N = 100;
int mon[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int main() {
  int res = 0;
  int y = 1999, m = 12, d = 31, w = 4;
  while(1) {
    ++d; w = (w + 1) % 7;
    if(d > mon[m]) {
      ++m; d = 1;
      if(m > 12) {
        ++y; m = 1;
        if((y % 4 == 0 && y % 100 != 0) || y % 400 == 0) mon[2] = 29; //閏年
        else mon[2] = 28;
      }
    }
    if(d == 1 || w == 0) ++res;
    ++res;
    //cout << y << " " << m << " " << d << " " << w << " " << res <<  "\n";
    if(y == 2020 && m == 10 && d == 1) break;
  }
  cout << res;
  return 0;
}

答案:8879

試題 E:七段碼(結果填空)

題意
在這里插入圖片描述
做法:二進制列舉再判斷選到的點是否連通(用dfs判斷),
代碼

#include<bits/stdc++.h>
using namespace std;
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define _for(n,m,i) for (int i = (n); i < (m); ++i)
#define _rep(n,m,i) for (int i = (n); i <= (m); ++i)
#define lson rt<<1, l, mid
#define rson rt<<1|1, mid+1, r
#define PI acos(-1)
#define eps 1e-8
#define rint int
typedef long long LL;
typedef pair<LL, int> pli;
typedef pair<int, int> pii;
typedef pair<double, int> pdi;
typedef pair<LL, LL> pll;
typedef pair<double, double> pdd;
typedef map<int, int> mii;
typedef map<char, int> mci;
typedef map<string, int> msi;
template<class T>
void read(T &res) {
  int f = 1; res = 0;
  char c = getchar();
  while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); }
  while(c >= '0' && c <= '9') { res = res * 10 + c - '0'; c = getchar(); }
  res *= f;
}
const int ne[8][2] = {1, 0, -1, 0, 0, 1, 0, -1, -1, -1, -1, 1, 1, -1, 1, 1};
const int INF = 0x3f3f3f3f;
const int N = 10;
const LL Mod = 1e9+7;
const int M = 1e6+10;
int a[10] = {0, 1, 2, 3, 4, 5, 6, 7};
int tu[N][N];
void init() {
  tu[0][0] = tu[0][1] = tu[0][2] = tu[0][3] = tu[0][4] = tu[0][5] = tu[0][6] = tu[0][7] = 1;
  tu[1][2] = tu[1][3] = 1;
  tu[2][1] = tu[2][4] = tu[2][5] = 1;
  tu[3][1] = tu[3][4] = tu[3][6] = 1;
  tu[4][2] = tu[4][3] = tu[4][5] = tu[4][6] = 1;
  tu[5][2] = tu[5][4] = tu[5][7] = 1;
  tu[6][3] = tu[6][4] = tu[6][7] = 1;
  tu[7][5] = tu[7][6] = 1;
}
int ans;
int fa[N];
void dfs(int u) {
  fa[u] = 0; 
  for(int i = 1; i <= 7; ++i) {
    if(tu[u][i] && fa[i]) dfs(i);
  }
}
int Find(int x) { return fa[x] == x ? x : fa[x] = Find(fa[x]); }
void solve (int x) {
  int f = 1;
  for(int i = 0; i < 7; ++i) 
    if((x>>i)&1) fa[i+1] = 1;
  for(int i = 1; i <= 7; ++i) {
    if(fa[i]) {
      dfs(i); break;
    }
  }
  for(int i = 1; i <= 7; ++i) {
    if(fa[i]) f = 0;
    fa[i] = 0;
  }
  ans += f;
}
int main() {
  init();
  for(int i = 1; i < (1 << 7); ++i) solve(i);
  cout << ans;
  return 0;
}

答案:80


試題 F:成績統計(程式設計)

題意:點此進入
統計成績的及格率和優秀率,

做法:直接貪心即可,

代碼

#include<bits/stdc++.h>
using namespace std;
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define _for(n,m,i) for (int i = (n); i < (m); ++i)
#define _rep(n,m,i) for (int i = (n); i <= (m); ++i)
#define lson rt<<1, l, mid
#define rson rt<<1|1, mid+1, r
#define PI acos(-1)
#define eps 1e-8
#define rint int
typedef long long LL;
typedef pair<LL, int> pli;
typedef pair<int, int> pii;
typedef pair<double, int> pdi;
typedef pair<LL, LL> pll;
typedef pair<double, double> pdd;
typedef map<int, int> mii;
typedef map<char, int> mci;
typedef map<string, int> msi;
template<class T>
void read(T &res) {
  int f = 1; res = 0;
  char c = getchar();
  while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); }
  while(c >= '0' && c <= '9') { res = res * 10 + c - '0'; c = getchar(); }
  res *= f;
}
const int ne[8][2] = {1, 0, -1, 0, 0, 1, 0, -1, -1, -1, -1, 1, 1, -1, 1, 1};
const int INF = 0x3f3f3f3f;
const int N = 3e5+10;
const LL Mod = 1e9+7;
const int M = 1e6+10;
int main() {
  int n; scanf("%d", &n);
  double jg = 0, yx = 0, x;
  _rep(1, n, i) {
    scanf("%lf", &x);
    if(x >= 85) ++yx;
    if(x >= 60) ++jg;
  }
  printf("%.0lf%\n%.0lf%\n", jg*100/n, yx*100/n);
  return 0;
}

試題 G:回文日期(結果填空)

題意:點此進入
計算出下一個回文型日期和ABABBABA日期,

做法:直接暴力判斷就好了,需要注意的點是A!=B,

代碼

#include<bits/stdc++.h>
using namespace std;
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define _for(n,m,i) for (int i = (n); i < (m); ++i)
#define _rep(n,m,i) for (int i = (n); i <= (m); ++i)
#define lson rt<<1, l, mid
#define rson rt<<1|1, mid+1, r
#define PI acos(-1)
#define eps 1e-8
#define rint int
typedef long long LL;
typedef pair<LL, int> pli;
typedef pair<int, int> pii;
typedef pair<double, int> pdi;
typedef pair<LL, LL> pll;
typedef pair<double, double> pdd;
typedef map<int, int> mii;
typedef map<char, int> mci;
typedef map<string, int> msi;
template<class T>
void read(T &res) {
  int f = 1; res = 0;
  char c = getchar();
  while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); }
  while(c >= '0' && c <= '9') { res = res * 10 + c - '0'; c = getchar(); }
  res *= f;
}
const int ne[8][2] = {1, 0, -1, 0, 0, 1, 0, -1, -1, -1, -1, 1, 1, -1, 1, 1};
const int INF = 0x3f3f3f3f;
const int N = 3e5+10;
const LL Mod = 1e9+7;
const int M = 1e6+10;
int mon[20] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool ishw(string s) {
  int l = 0, r = s.size()-1;
  while(l < r) {
    if(s[l] != s[r]) return false;
    ++l; --r;
  }
  return true;
}
bool isAB(string s) {
  if(s[0] == s[2] && s[0] == s[5] && s[5] == s[7]) 
    if(s[1] == s[3] && s[3] == s[4] && s[4] == s[6])
      if(s[0] != s[1]) return true;
  return false;
}
int main() {
  int n; scanf("%d", &n);
  int y = n / 10000, m = (n / 100) % 100, d = n % 100;
  if((y % 4 == 0 && y % 100) || y % 400 == 0) mon[2] = 29;
  string s, hw, AB;
  int fhw = 1, fAB = 1;
  while(fhw || fAB) {
    ++d;
    if(d > mon[m]) {
      ++m; d = 1;
      if(m > 12) {
        ++y; m = 1;
        if((y % 4 == 0 && y % 100) || y % 400 == 0) mon[2] = 29;
      }
    }
    s = (char)((y/1000%10)+'0');
	s += (char)((y/100%10)+'0');
	s += char(y/10%10+'0');
	s += char(y%10+'0');
    s += char(m/10%10+'0');
	s += char(m%10+'0');
	s += char(d/10%10+'0');
	s += char(d%10+'0');
    if(fhw && ishw(s)) fhw = 0, hw = s;
    if(fAB && isAB(s)) fAB = 0, AB = s;
  }
  cout << hw << "\n" << AB << "\n";
  return 0;
}

答案


試題 H:子串分值和(程式設計)

題意:點此進入
在這里插入圖片描述

做法:50分的資料方法挺多的,記錄字母前綴和再列舉等等,而100分的做法其實是最短小的(又是考場做不出來系列),正確做法復雜度是O(n),統計每個字母的貢獻,即這個字母出現在多少個區間中,權值和就是答案,而“每個字母出現在多少個區間中”用如下公式: ( i ? p r e [ s [ i ] ? ′ a ′ ] ) ? ( l e n ? i + 1 ) (i-pre[s[i]-'a']) * (len-i+1) (i?pre[s[i]?a])?(len?i+1),其中pre[s[i]-‘a’]代表的是上一個相同字母出現的位置, 而這個公式計算的是,包含i左端點的數量*包含i右端點的數量,要減去上一個相同字母出現的位置是防止重復計算(想不出來系列),

代碼

#include<bits/stdc++.h>
using namespace std;
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define _for(n,m,i) for (int i = (n); i < (m); ++i)
#define _rep(n,m,i) for (int i = (n); i <= (m); ++i)
#define lson rt<<1, l, mid
#define rson rt<<1|1, mid+1, r
#define PI acos(-1)
#define eps 1e-8
#define rint int
typedef long long LL;
typedef pair<LL, int> pli;
typedef pair<int, int> pii;
typedef pair<double, int> pdi;
typedef pair<LL, LL> pll;
typedef pair<double, double> pdd;
typedef map<int, int> mii;
typedef map<char, int> mci;
typedef map<string, int> msi;
template<class T>
void read(T &res) {
  int f = 1; res = 0;
  char c = getchar();
  while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); }
  while(c >= '0' && c <= '9') { res = res * 10 + c - '0'; c = getchar(); }
  res *= f;
}
const int ne[8][2] = {1, 0, -1, 0, 0, 1, 0, -1, -1, -1, -1, 1, 1, -1, 1, 1};
const int INF = 0x3f3f3f3f;
const int N = 3e5+10;
const LL Mod = 1e9+7;
const int M = 1e6+10;
int pre[30];
char s[N];
int main() {
  scanf("%s", s+1);
  int len = strlen(s+1);
  LL res = 0;
  _rep(1, len, i) {
    res += 1ll * (i-pre[s[i]-'a']) * (len-i+1);
    pre[s[i]-'a'] = i;
  }
  cout << res;
  return 0;
}

轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/275506.html

標籤:其他

上一篇:H5音樂播放器(包含原始碼與示例)

下一篇:2021-04-12

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • 【從零開始擼一個App】Dagger2

    Dagger2是一個IOC框架,一般用于Android平臺,第一次接觸的朋友,一定會被搞得暈頭轉向。它延續了Java平臺Spring框架代碼碎片化,注解滿天飛的傳統。嘗試將各處代碼片段串聯起來,理清思緒,真不是件容易的事。更不用說還有各版本細微的差別。 與Spring不同的是,Spring是通過反射 ......

    uj5u.com 2020-09-10 06:57:59 more
  • Flutter Weekly Issue 66

    新聞 Flutter 季度調研結果分享 教程 Flutter+FaaS一體化任務編排的思考與設計 詳解Dart中如何通過注解生成代碼 GitHub 用對了嗎?Flutter 團隊分享如何管理大型開源專案 插件 flutter-bubble-tab-indicator A Flutter librar ......

    uj5u.com 2020-09-10 06:58:52 more
  • Proguard 常用規則

    介紹 Proguard 入口,如何查看輸出,如何使用 keep 設定入口以及使用實體,如何配置壓縮,混淆,校驗等規則。

    ......

    uj5u.com 2020-09-10 06:59:00 more
  • Android 開發技術周報 Issue#292

    新聞 Android即將獲得類AirDrop功能:可向附近設備快速分享檔案 谷歌為安卓檔案管理應用引入可安全隱藏資料的Safe Folder功能 Android TV新主界面將顯示電影、電視節目和應用推薦內容 泄露的Android檔案暗示了傳說中的谷歌Pixel 5a與折疊屏新機 谷歌發布Andro ......

    uj5u.com 2020-09-10 07:00:37 more
  • AutoFitTextureView Error inflating class

    報錯: Binary XML file line #0: Binary XML file line #0: Error inflating class xxx.AutoFitTextureView 解決: <com.example.testy2.AutoFitTextureView android: ......

    uj5u.com 2020-09-10 07:00:41 more
  • 根據Uri,Cursor沒有獲取到對應的屬性

    Android: 背景:呼叫攝像頭,拍攝視頻,指定保存的地址,但是回傳的Cursor檔案,只有名稱和大小的屬性,沒有其他諸如時長,連ID屬性都沒有 使用 cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DURATIO ......

    uj5u.com 2020-09-10 07:00:44 more
  • Android連載29-持久化技術

    一、持久化技術 我們平時所使用的APP產生的資料,在記憶體中都是瞬時的,會隨著斷電、關機等丟失資料,因此android系統采用了持久化技術,用于存盤這些“瞬時”資料 持久化技術包括:檔案存盤、SharedPreference存盤以及資料庫存盤,還有更復雜的SD卡記憶體儲。 二、檔案存盤 最基本存盤方式, ......

    uj5u.com 2020-09-10 07:00:47 more
  • Android Camera2Video整合到自己專案里

    背景: Android專案里呼叫攝像頭拍攝視頻,原本使用的 MediaStore.ACTION_VIDEO_CAPTURE, 后來因專案需要,改成了camera2 1.Camera2Video 官方demo有點問題,下載后,不能直接整合到專案 問題1.多次拍攝視頻崩潰 問題2.雙擊record按鈕, ......

    uj5u.com 2020-09-10 07:00:50 more
  • Android 開發技術周報 Issue#293

    新聞 谷歌為Android TV開發者提供多種新功能 Android 11將自動填表功能整合到鍵盤輸入建議中 谷歌宣布Android Auto即將支持更多的導航和數字停車應用 谷歌Pixel 5只有XL版本 搭載驍龍765G且將比Pixel 4更便宜 [圖]Wear OS將迎來重磅更新:應用啟動時間 ......

    uj5u.com 2020-09-10 07:01:38 more
  • 海豚星空掃碼投屏 Android 接收端 SDK 集成 六步驟

    掃碼投屏,開放網路,獨占設備,不需要額外下載軟體,微信掃碼,發現設備。支持標準DLNA協議,支持倍速播放。視頻,音頻,圖片投屏。好點意思。還支持自定義基于 DLNA 擴展的操作動作。好像要收費,沒體驗。 這里簡單記錄一下集成程序。 一 跟目錄的build.gradle添加私有mevan倉庫 mave ......

    uj5u.com 2020-09-10 07:01:43 more
最新发布
  • 歡迎頁輪播影片

    如圖,引導開始,球從上落下,同時淡入文字,然后文字開始輪播,最后一頁時停止,點擊進入首頁。 在來看看效果圖。 重力球先不講,主要歡迎輪播簡單實作 首先新建一個類 TextTranslationXGuideView,用于影片展示 文本是類似的,最后會有個圖片箭頭影片,布局很簡單,就是一個 TextVi ......

    uj5u.com 2023-04-20 08:40:31 more
  • 【FAQ】關于華為推送服務因營銷訊息頻次管控導致服務通訊類訊息

    一. 問題描述 使用華為推送服務下發IM訊息時,下發訊息請求成功且code碼為80000000,但是手機總是收不到訊息; 在華為推送自助分析(Beta)平臺查看發現,訊息發送觸發了頻控。 二. 問題原因及背景 2023年1月05日起,華為推送服務對咨詢營銷類訊息做了單個設備每日推送數量上限管理,具體 ......

    uj5u.com 2023-04-20 08:40:11 more
  • 歡迎頁輪播影片

    如圖,引導開始,球從上落下,同時淡入文字,然后文字開始輪播,最后一頁時停止,點擊進入首頁。 在來看看效果圖。 重力球先不講,主要歡迎輪播簡單實作 首先新建一個類 TextTranslationXGuideView,用于影片展示 文本是類似的,最后會有個圖片箭頭影片,布局很簡單,就是一個 TextVi ......

    uj5u.com 2023-04-20 08:39:36 more
  • 【FAQ】關于華為推送服務因營銷訊息頻次管控導致服務通訊類訊息

    一. 問題描述 使用華為推送服務下發IM訊息時,下發訊息請求成功且code碼為80000000,但是手機總是收不到訊息; 在華為推送自助分析(Beta)平臺查看發現,訊息發送觸發了頻控。 二. 問題原因及背景 2023年1月05日起,華為推送服務對咨詢營銷類訊息做了單個設備每日推送數量上限管理,具體 ......

    uj5u.com 2023-04-20 08:39:13 more
  • iOS從UI記憶體地址到讀取成員變數(oc/swift)

    開發除錯時,我們發現bug時常首先是從UI顯示發現例外,下一步才會去定位UI相關連的資料的。XCode有給我們提供一系列debug工具,但是很多人可能還沒有形成一套穩定的除錯流程,因此本文嘗試解決這個問題,順便提出一個暴論:UI顯示例外問題只需要兩個步驟就能完成定位作業的80%: 定位例外 UI 組 ......

    uj5u.com 2023-04-19 09:16:23 more
  • FIDE重磅更新!性能飛躍!體驗有禮!

    FIDE 開發者工具重構升級啦!實作500%性能提升,誠邀體驗! 一直以來不少開發者朋友在社區反饋,在使用 FIDE 工具的程序中,時常會遇到諸如加載不及時、代碼預覽/渲染性能不如意的情況,十分影響開發體驗。 作為技術團隊,我們深知一件趁手的開發工具對開發者的重要性,因此,在2023年開年,FinC ......

    uj5u.com 2023-04-19 09:16:15 more
  • 游戲內嵌社區服務開放,助力開發者提升玩家互動與留存

    華為 HMS Core 游戲內嵌社區服務提供快速訪問華為游戲中心論壇能力,支持玩家直接在游戲內瀏覽帖子和交流互動,助力開發者擴展內容生產和觸達的場景。 一、為什么要游戲內嵌社區? 二、游戲內嵌社區的典型使用場景 1、游戲內打開論壇 您可以在游戲內繪制論壇入口,為玩家提供沉浸式發帖、瀏覽、點贊、回帖、 ......

    uj5u.com 2023-04-19 09:15:46 more
  • iOS從UI記憶體地址到讀取成員變數(oc/swift)

    開發除錯時,我們發現bug時常首先是從UI顯示發現例外,下一步才會去定位UI相關連的資料的。XCode有給我們提供一系列debug工具,但是很多人可能還沒有形成一套穩定的除錯流程,因此本文嘗試解決這個問題,順便提出一個暴論:UI顯示例外問題只需要兩個步驟就能完成定位作業的80%: 定位例外 UI 組 ......

    uj5u.com 2023-04-19 09:14:53 more
  • FIDE重磅更新!性能飛躍!體驗有禮!

    FIDE 開發者工具重構升級啦!實作500%性能提升,誠邀體驗! 一直以來不少開發者朋友在社區反饋,在使用 FIDE 工具的程序中,時常會遇到諸如加載不及時、代碼預覽/渲染性能不如意的情況,十分影響開發體驗。 作為技術團隊,我們深知一件趁手的開發工具對開發者的重要性,因此,在2023年開年,FinC ......

    uj5u.com 2023-04-19 09:14:08 more
  • 游戲內嵌社區服務開放,助力開發者提升玩家互動與留存

    華為 HMS Core 游戲內嵌社區服務提供快速訪問華為游戲中心論壇能力,支持玩家直接在游戲內瀏覽帖子和交流互動,助力開發者擴展內容生產和觸達的場景。 一、為什么要游戲內嵌社區? 二、游戲內嵌社區的典型使用場景 1、游戲內打開論壇 您可以在游戲內繪制論壇入口,為玩家提供沉浸式發帖、瀏覽、點贊、回帖、 ......

    uj5u.com 2023-04-19 09:08:34 more