十四届蓝桥杯第三期模拟赛(C/C++ C组)
A
参考答案
2730
思路
进制转换,电脑自带计算器即可完成
十进制下输入2022,十六进制为7E6,那么只需十六进制下输入AAA找到对应的十进制数即可
代码
#include<iostream>
using namespace std;
bool check(int x)
{
while(x)
{
if(x % 16 >= 10 && x % 16 <= 15);
else return false;
x /= 16;
}
return true;
}
int main()
{
for(int i = 2023; ; i ++)
{
if(check(i))
{
cout << i;
return 0;
}
}
return 0;
}
B
参考答案
BYT
思路
26进制,最简单的方法Excel表拉一下即可
#include<iostream>
using namespace std;
char ch[26] = {'A' , 'B' , 'C' , 'D' , 'E' , 'F' , 'G' , 'H' , 'I' , 'J' ,
'K' , 'L' , 'M' , 'N' , 'O' , 'P' , 'Q' , 'R' , 'S' , 'T' ,
'U' , 'V' , 'W' , 'X' , 'Y' , 'Z'};
int a[5];
int main()
{
int x = 2022;
int j = 0;
while(x)
{
a[j ++] = x % 26;
x /= 26;
}
while(j --) cout << ch[a[j] - 1];
return 0;
}
C
参考答案
70910
思路
模拟即可,注意闰年判断,日期合法
#include<iostream>
using namespace std;
typedef long long ll;
int month[13] = {0 , 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31};
ll ans;//计数
bool is_leap(int year)//判断闰年
{
return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
}
int get(int x)//得到数位和
{
int n = 0;
while(x)
{
n += x % 10;
x /= 10;
}
return n;
}
bool check(int y , int m , int d)//判断是否成立
{
if(get(y) == (get(m) + get(d))) return true;
else return false;
}
int main()
{
for(int i = 1900; i <= 9999; i ++)
for(int j = 1; j <= 12; j ++)
{
int l = month[j];
if(is_leap(i) && j == 2) l ++;
for(int k = 1; k <= l; k ++) if(check(i , j , k)) ans ++;
}
cout << ans;
return 0;
}
D
参考答案
189
思路
枚举即可
#include<iostream>
using namespace std;
int nums[31] = {0, 99, 22, 51, 63, 72, 61, 20, 88, 40, 21, 63, 30, 11, 18, 99, 12, 93, 16, 7, 53, 64, 9, 28, 84, 34, 96, 52, 82, 51, 77};
int ans;
int main()
{
for(int i = 1; i <= 30; i ++)
for(int j = i + 1; j <= 30; j ++)
if(nums[i] * nums[j] >= 2022) ans ++;
cout << ans ;
return 0;
}
E
参考答案
148
思路
暴搜即可
F
思路
模拟即可
#include <iostream>
using namespace std;
int w , n;
int main()
{
cin >> w >> n;
if((w + n) % 7)
cout << (w + n) % 7;
else
cout << 7;
return 0;
}
G
思路
两点之间的距离≤半径
#include <cmath>
using namespace std;
int num[105][105];
int W, H, n, R;
int ans;
double distance(int x1, int y1, int x2, int y2)
{
return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
int main()
{
cin >> W >> H >> n >> R;
while(n --)
{
int x, y;
cin >> x >> y;
for (int i = x - R; i <= x + R; i ++)
for (int j = y - R; j <= y + R; j ++)
if (i >= 0 && i <= W && j >= 0 && j <= H && distance(x, y, i, j) <= R)
num[i][j] = 1;
}
for (int i = 0; i <= W; i++)
for (int j = 0; j <= H; j++)
if (num[i][j] == 1)
ans ++;
cout << ans << endl;
return 0;
}
H
思路
字符串转化为小写,对比一下即可
#include <iostream>
#include <cstring>
using namespace std;
string s1;
int main()
{
cin >> s1;
string s2 = "lanqiao";
for(int i = 0; i < s1.size(); i ++) s1[i] = tolower(s1[i]);
if(s1.size() == s2.size() && s2 == s1) cout << "yes";
else cout << "no";
return 0;
}
I
思路
考查二维差分,数据量比较小暴力也能做
#include<iostream>
using namespace std;
int W , H , n;
int num[110][110];
int ans;
int main()
{
cin >> W >> H >> n;
while(n --)
{
int x1 , y1 , x2 , y2;
cin >> x1 >> y1 >> x2 >> y2;
for(int i = x1; i <= x2 ; i ++)
for(int j = y1 ; j <= y2; j ++)
{
if(num[i][j] == 0)
{
num[i][j] = 1;
ans ++;
}
}
}
cout << W * H - ans;
return 0;
}
J
思路
板子题,记忆化搜索