第十一届蓝桥杯大赛软件赛省赛第二场 C/C++ 大学B组
生活随笔
收集整理的這篇文章主要介紹了
第十一届蓝桥杯大赛软件赛省赛第二场 C/C++ 大学B组
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
試題A :門(mén)牌制作
// 624 #include <iostream> using namespace std;int solve(int x) {int res = 0;while (x){if (x % 10 == 2) res ++ ;x /= 10;}return res; }int main() {int res = 0;for (int i = 1; i <= 2020; i ++ ){res += solve(i);}cout << res; }試題B :既約分?jǐn)?shù)
// 2481215 #include <iostream> using namespace std;int gcd(int a, int b) {return b ? gcd(b, a % b) : a; }int main() {int res = 0;for (int fenzi = 1; fenzi <= 2020; fenzi ++ )for (int fenmu = 1; fenmu <= 2020; fenmu ++ ){if (gcd(fenzi, fenmu) == 1)res ++ ;}cout << res; }試題C :蛇形填數(shù)
// 761 #include <iostream> using namespace std;int cnt = 1; int g[100][100];int main() {int x = 1, y = 1;while (cnt <= 3000){// 1g[x][y] = cnt ++ ;// 2y ++ ;for ( ; y >= 1; x ++ , y -- )g[x][y] = cnt ++ ;x -- , y ++ ;// 3x ++ ;for ( ; x >= 2; x -- , y ++ )g[x][y] = cnt ++ ;}cout << g[20][20]; }試題D :跑步鍛煉
// 8879 #include <iostream> using namespace std;int months[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};int get_day(int year, int month) {if (month != 2) return months[month];if ((year % 400 == 0) || (year % 4 == 0 && year % 100 != 0)) return 29;return 28; }int main() {int sum = 0, res = 0;for (int i = 2000; i <= 2019; i ++ ){for (int j = 1; j <= 12; j ++ ){for (int k = 1; k <= get_day(i, j); k ++ ){int weekend = (sum % 7 + 5) % 7;if (k == 1 || weekend == 0) res += 2;else res ++ ;sum ++ ;}}}for (int i = 1; i <= 9; i ++ ){for (int j = 1; j <= get_day(2020, i); j ++ ){int weekend = (sum % 7 + 5) % 7;if (j == 1 || weekend == 0) res += 2;else res ++ ;sum ++ ;}}res += 2;cout << res; }試題E :七段碼
- dfs+并查集
試題F :成績(jī)統(tǒng)計(jì)
#include <iostream> using namespace std;int main() {int n; cin >> n;int jige = 0, youxiu = 0;for (int i = 0; i < n; i ++ ){int grade; cin >> grade;if (grade >= 60) jige ++ ;if (grade >= 85) youxiu ++ ;}cout << (int)(100.0 * jige / n + 0.5) << '%' << endl;cout << (int)(100.0 * youxiu / n + 0.5) << '%' << endl; }試題G :回文日期
- 直接枚舉回文數(shù),再來(lái)判斷合法性
試題H :子串分值和
- 算每一個(gè)位置的貢獻(xiàn)
- 因?yàn)槭撬忝總€(gè)連續(xù)子串中不同字符的個(gè)數(shù),因此 對(duì)于原字符串中所有相同的字符而言,每一個(gè)字符做出的貢獻(xiàn)中,當(dāng)前子串必然不包含上一次這個(gè)字符出現(xiàn)的位置及以前,包含這個(gè)字符出現(xiàn)的位置至原字符串末尾
試題I :平面切分
- 每增加一條直線,它對(duì)答案的貢獻(xiàn)是 它與之前直線的所有交點(diǎn)(要去重)個(gè)數(shù)+1
- 直線本身也需要去重
- 因此,兩次用到set
- 計(jì)算交點(diǎn)的時(shí)候,注意分母為0情況
- 易錯(cuò)點(diǎn) :涉及直線或點(diǎn),經(jīng)常要用到set容器來(lái)去重,且每次計(jì)算分式必然要討論分母為零的情況
試題J :字串排序
總結(jié)
以上是生活随笔為你收集整理的第十一届蓝桥杯大赛软件赛省赛第二场 C/C++ 大学B组的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 计算机组成原理(哈工大刘宏伟)135讲(
- 下一篇: 第十届蓝桥杯大赛软件赛省赛 C/C++