A组
门牌制作
#include <iostream>
using namespace std;
int get(int x)
{
int res = 0;
while (x)
{
res += x % 10 == 2;
x /= 10;
}
return res;
}
int main()
{
int cnt = 0;
for (int i = 1; i <= 2020; i ++ )
{
cnt += get(i);
}
cout << cnt << endl;
return 0;
}
既约分数
#include <iostream>
using namespace std;
int gcd(int a, int b)
{
return b ? gcd(b, a % b) : a;
}
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 << endl;
return 0;
}
B组
空间
#include <iostream>
using namespace std;
int main()
{
cout << 256 * 1024 * 1024 / 4 << endl;
return 0;
}
卡片
#include <iostream>
using namespace std;
int a[10];
bool check(int x)
{
while (x)
{
if (--a[x % 10] < 0) return false;
x /= 10;
}
return true;
}
int main()
{
int i;
for (i = 0; i <= 9; i ++ ) a[i] = 2021;
for (i = 1; i; i ++ )
{
if (!check(i)) break;
}
cout << i - 1 << endl;
return 0;
}
C组
报纸页数
#include <iostream>
using namespace std;
int main()
{
cout << 1125 + 1727 << endl;
return 0;
}
猴子分香蕉
#include <iostream>
using namespace std;
bool check(int x)
{
for (int i = 1; i <= 4; i ++ )
{
if (x % 5 != i) return false;
x -= i;
x /= 5;
x *= 4;
}
return x % 5 == 0 && !x;
}
int main()
{
for (int i = 1; i <= 1000000; i += 5)
{
if (check(i))
{
cout << i << endl;
return 0;
}
}
return 0;
}
|