2020第十一届11月蓝桥杯大赛软件类B组C/C++省赛目录
试题 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