A.
Brute force calculation is enough.
// #pragma GCC optimize(2)
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <sstream>
#include <cstring>
#include <set>
#include <cctype>
#include <bitset>
#define IO \
ios::sync_with_stdio(false); \
// cout.tie(0);
using namespace std;
// int dis[8][2] = {0, 1, 1, 0, 0, -1, -1, 0, 1, -1, 1, 1, -1, 1, -1, -1};
typedef unsigned long long ULL;
typedef long long LL;
typedef pair<int, int> P;
const int maxn = 2e8 + 10;
const int maxm = 2e5 + 10;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const LL mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);
int dis[4][2] = {1, 0, 0, -1, 0, 1, -1, 0};
int m[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int ans = 0;
int count(int n)
{
int cnt = 0;
while (n)
{
int t = n % 10;
if (t == 2)
cnt++;
n = n / 10;
}
return cnt;
}
int main()
{
#ifdef WXY
freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
#endif
IO;
for (int i = 1; i <= 2020; i++)
ans += count(i);
cout << ans;
return 0;
}
624
It is easy to find the rule to find the relationship between two adjacent items.
// #pragma GCC optimize(2)
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <sstream>
#include <cstring>
#include <set>
#include <cctype>
#include <bitset>
#define IO \
ios::sync_with_stdio(false); \
// cout.tie(0);
using namespace std;
// int dis[8][2] = {0, 1, 1, 0, 0, -1, -1, 0, 1, -1, 1, 1, -1, 1, -1, -1};
typedef unsigned long long ULL;
typedef long long LL;
typedef pair<int, int> P;
const int maxn = 2e8 + 10;
const int maxm = 2e5 + 10;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const LL mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);
int dis[4][2] = {1, 0, 0, -1, 0, 1, -1, 0};
int m[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int main()
{
#ifdef WXY
freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
#endif
IO;
int a[50];
int t = 1;
a[1] = 1;
for (int i = 2; i <= 20;i++)
a[i] = a[i - 1] + t * 4, t++;
cout << a[20];
return 0;
}
761
C.
Violent judgment is enough.
// #pragma GCC optimize(2)
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <sstream>
#include <cstring>
#include <set>
#include <cctype>
#include <bitset>
#define IO \
ios::sync_with_stdio(false); \
// cout.tie(0);
using namespace std;
// int dis[8][2] = {0, 1, 1, 0, 0, -1, -1, 0, 1, -1, 1, 1, -1, 1, -1, -1};
typedef unsigned long long ULL;
typedef long long LL;
typedef pair<int, int> P;
const int maxn = 2e8 + 10;
const int maxm = 2e5 + 10;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const LL mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);
int dis[4][2] = {1, 0, 0, -1, 0, 1, -1, 0};
int m[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int gcd(int a, int b)
{
if (b == 0)
return a;
else
return gcd(b, a % b);
}
int main()
{
#ifdef WXY
freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
#endif
IO;
int ans = 0;
for (int i = 1; i <= 2020; i++)
for (int j = 1; j <= 2020; j++)
if (gcd(i, j) == 1)
ans++;
cout << ans;
return 0;
}
2481215
D.
Because I was afraid of counting fans during the game, I didn't use the calendar to count. Now I think about counting it when I really need to check.
I wrote 8880 for this question because the function return value is printed (calling the function will cause the global variable to change), but if you use a variable to store the return value of the function, it won’t be wrong. . . Save it. . . .
// #pragma GCC optimize(2)
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <sstream>
#include <cstring>
#include <set>
#include <cctype>
#include <bitset>
#define IO \
ios::sync_with_stdio(false); \
// cout.tie(0);
using namespace std;
// int dis[8][2] = {0, 1, 1, 0, 0, -1, -1, 0, 1, -1, 1, 1, -1, 1, -1, -1};
typedef unsigned long long ULL;
typedef long long LL;
typedef pair<int, int> P;
const int maxn = 2e8 + 10;
const int maxm = 2e5 + 10;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const LL mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);
int dis[4][2] = {1, 0, 0, -1, 0, 1, -1, 0};
int m[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int w = 5;
bool rui(int n)
{
if (n % 400 == 0 || (n % 4 == 0 && n % 100 != 0))
return true;
return false;
}
int count(int year)
{
int cnt = 0;
if (rui(year))
m[2] += 1;
if (year == 2020)
{
for (int i = 1; i <= 9; i++)
{
for (int j = 1; j <= m[i]; j++)
{
if (w == 0 || j == 1)
{
cnt++;
}
w = (w + 1) % 7;
}
}
}
else
{
for (int i = 1; i <= 12; i++)
{
for (int j = 1; j <= m[i]; j++)
{
if (w == 0 || j == 1)
{
cnt++;
}
w = (w + 1) % 7;
}
}
}
if (rui(year))
m[2] -= 1;
return cnt;
}
int main()
{
#ifdef WXY
freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
#endif
IO;
int ans = 0;
for (int i = 2000; i <= 2020; i++)
{
// cout << count(i) << endl;
// 一念之间 天堂地狱
// 闲的没事非打印干嘛?!
// 打印完了还不注释掉?!
ans += count(i);
}
cout << ans + 7580 + 1; // 最后再加上10.1这一天
return 0;
}
E.
You can use a two-dimensional array to build a map and then run bfs to determine whether it is connected.
#include<bits/stdc++.h>
using namespace std;
int dis[6][2] = {1, -1, -1, 1, -1, -1, 1, 1, 2, 0, -2, 0};
struct Node
{
int x, y;
Node(){};
Node(int a, int b)
{
x = a, y = b;
}
};
int g[10][10];
bool book[10][10];
bool vis[10];
int a[10];
int C, ans;
bool BFS(int all)
{
memset(book, false, sizeof book);
int sx, sy;
for (int i = 1; i <= 5; i++)
for (int j = 1; j <= 3; j++)
if (g[i][j] == 1)
{
sx = i, sy = j;
break;
}
queue<Node> q;
q.push(Node(sx, sy));
book[sx][sy] = true;
int cnt = 0;
while (!q.empty())
{
Node now = q.front();
q.pop();
cnt++;
if (now.y == 2)
{
for (int i = 0; i < 4; i++)
{
int tx = now.x + dis[i][0];
int ty = now.y + dis[i][1];
if (tx >= 1 && tx <= 5 && ty >= 1 && ty <= 3 && g[tx][ty] == 1 && book[tx][ty] == false)
{
book[tx][ty] = true;
q.push(Node(tx, ty));
}
}
}
else
{
for (int i = 0; i < 6; i++)
{
int tx = now.x + dis[i][0];
int ty = now.y + dis[i][1];
if (tx >= 1 && tx <= 5 && ty >= 1 && ty <= 3 && g[tx][ty] == 1 && book[tx][ty] == false)
{
book[tx][ty] = true;
q.push(Node(tx, ty));
}
}
}
}
return cnt == all;
}
void draw(int val)
{
if (val == 1)
g[1][2] = 1;
if (val == 2)
g[2][3] = 1;
if (val == 3)
g[4][3] = 1;
if (val == 4)
g[5][2] = 1;
if (val == 5)
g[4][1] = 1;
if (val == 6)
g[2][1] = 1;
if (val == 7)
g[3][2] = 1;
return;
}
void DFS(int now, int sum)
{
if (sum == C)
{
memset(g, 0, sizeof g);
for (int i = 0; i < sum; i++)
draw(a[i]);
if (BFS(sum))
ans++;
return;
}
for (int i = now; i <= 7; i++)
{
if (vis[i] == false)
{
vis[i] = true;
a[sum] = i;
DFS(i + 1, sum + 1);
vis[i] = false;
}
}
return;
}
int main()
{
for (int i = 1; i <= 7; i++)
{
C = i;
DFS(1, 0);
}
cout << ans;
return 0;
}
80
F
// #pragma GCC optimize(2)
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <sstream>
#include <cstring>
#include <set>
#include <cctype>
#include <bitset>
#define IO \
ios::sync_with_stdio(false); \
// cout.tie(0);
using namespace std;
// int dis[8][2] = {0, 1, 1, 0, 0, -1, -1, 0, 1, -1, 1, 1, -1, 1, -1, -1};
typedef unsigned long long ULL;
typedef long long LL;
typedef pair<int, int> P;
const int maxn = 2e8 + 10;
const int maxm = 2e5 + 10;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const LL mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);
int dis[6][2] = {1, -1, -1, 1, -1, -1, 1, 1, 2, 0, -2, 0};
int m[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int main()
{
#ifdef WXY
freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
#endif
IO;
int n, x;
int cnt1, cnt2 = 0;
char c = '%';
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> x;
if (x >= 60)
cnt1++;
if (x >= 85)
cnt2++;
}
printf("%.0lf", round(100.0 * double(cnt1) / double(n)));
printf("%c\n", c);
printf("%.0lf", round(100.0 * double(cnt2) / double(n)));
printf("%c", c);
return 0;
}
G
At that time, I wrote a 200+ mentally handicapped violence (not necessarily correct). In fact, I only need to enumerate the years to construct a palindrome, and then save the eligible dates to divide the answer.
H
It’s too disheveled but only violently, O(n^3)
I
Sample output
If you think about it carefully, you should be able to violently simulate the situation of n<=4. .
J
Sample output
Not surprisingly, the province should be gone, it's still too food. . . .