intmain(){ longlong res = 1; for (int i = 1; i <= 2021; i += 2) { res = res * i % 100000; } cout << res; return0; }
ans:59375
格点
提示:
暴力一下就出来,花不了多少时间
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include<iostream>
usingnamespace std;
intmain(){ longlong x, y; int ans = 0; for (x = 1; x <= 2021; x++) { for (y = 1; y <= 2021; y++) { if (x * y <= 2021){ ans += 1; } } } cout << ans; }
ans:15698
整数分解
提示:
枚举前3个数,最后两个数只有m-1种情况, 注意一下int的数据范围问题
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include<iostream>
usingnamespace std;
intmain(){ longlong ans = 0; for (int i = 1; i < 2021; ++i) { for (int j = 1; j < 2021; ++j) { for (int k = 1; k < 2021; ++k) { int m = 2021 - i - j - k; if (m <= 1) break; ans += m - 1; } } } cout << ans; }
typedefstruct { int begin; int end; int weight; } Edge;
intcalculateWeight(int a, int b){ int res = 0; string sa = to_string(a), sb = to_string(b); while (sa.size() < sb.size()) sa = "0" + sa; // 因为 枚举时 a <b 所以 只可能是a要补前导0 for (int i = 0; i < sa.size(); ++i) { if (sa[i] != sb[i]) res += sa[i] - '0' + sb[i] - '0'; } return res; }
intFind(constint *parent, int f){ while (parent[f] > 0) f = parent[f]; return f; }
intmain(){ vector<Edge> M; // 构建边集数组 for (int i = 0; i < 2021; ++i) { for (int j = i + 1; j < 2021; ++j) { Edge edge; edge.begin = i; edge.end = j; edge.weight = calculateWeight(i + 1, j + 1); M.push_back(edge); } } sort(M.begin(), M.end(), myCompare); int maxVex = M.size(); int parent[maxVex]; for (int i = 0; i < maxVex; ++i) { parent[i] = 0; // 初始化数组值为0 }
longlong res = 0; for (int i = 0; i < maxVex; ++i) { // 循环每一条边 int n = Find(parent, M[i].begin); int m = Find(parent, M[i].end); if (n != m) { parent[n] = m; res += M[i].weight; } } cout << res << endl; return0;
}
ans:4046
特殊年份
提示:
读入之后判断一下即可;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include<iostream> #include<string>
usingnamespace std;
intmain(){ string a; int res = 0; for (int i = 0; i < 5; ++i) { cin >> a; if (a[0] == a[2] and a[3] - a[1] == 1) res += 1; } cout << res; return0; }