#include<bits/stdc++.h> usingnamespace std; constint N = 1e5 + 5; int n; vector<vector<int>> child(N); intdfs(int u) { int ret = 0; for (int v : child[u]) ret = max(ret, dfs(v)); return ret + child[u].size(); } signedmain() { scanf("%d", &n); int r; for (int i = 2; i <= n; i++) { scanf("%d", &r); child[r].push_back(i); } printf("%d", dfs(1)); return0; }
int cnt = 1, n = 1; while (cnt < 2025) { n += 2; bool prime = true; for (int i = 3; i < n; i += 2) { if (n % i == 0) { prime = false; break; } } if (prime) { ++cnt; } } cout << n << endl;
get 10/10 使用瞪眼法,一眼顶针,红黑树看出是异或运算,多往下画两行就发现,颜色和行数无关。把红和黑分别看作0和1,颜色就是异或1的运算。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
int n, m, k; cin >> m; while (m--) { cin >> n >> k; int a = 0; --k; while (k) { a ^= (k & 1); k >>= 1; } if (a) cout << "BLACK" << endl; else cout << "RED" << endl; }
#include<bits/stdc++.h> usingnamespace std; #define ll unsigned long long #define N 500005 constint p = 1000000007;
int n, m; unordered_map<ll, int> mp;//对每个数,对应的数量。unordered_map比map更高效 ll jc[N]; // 阶乘 ll inverse(ll a)//快速幂逆元 { ll b = p - 2, ret = 1; while (b) { if (b & 1) ret = ret * a % p; a = a * a % p; b >>= 1; } return ret; } signedmain() { jc[0] = jc[1] = 1; for (int i = 2; i < N; ++i) { jc[i] = jc[i - 1] * i % p; } scanf("%d", &n); m = n - 2;//矩阵的大小 ll a, b = 1, rc = 0; for (int i = 0; i < n; ++i) { scanf("%lld", &a); ++mp[a]; } for (auto i : mp) { b = b * jc[i.second] % p; } for (auto r : mp) { if (m % r.first != 0) continue; auto c = mp.find(m / r.first); if (c == mp.end()) // 找不到两数相乘为n-2 continue; if (r.first != c->first) rc = (rc + r.second * c->second % p) % p; else rc = (rc + r.second * (r.second - 1) % p) % p; } cout << jc[n - 2] * inverse(b) % p * rc % p << endl; return0; }
```cpp #include <bits/stdc++.h> using ll = long long; using ull = unsigned long long; const int N = (2e5) + 5; const double pi2 = 2 * M_PI; // 2*圆周率pi using namespace std;
struct point { int id; // 序号 int z; // 碰到增加的值 ull r; // 半径的平方 double angle; // 角度(以从y轴正方向开始的顺时针角度表示) bool operator>(const point &other) const { return angle > other.angle; // 优先队列按角度排序 } } p[N];
int main() { int n;//棒的个数 ull l;//棒的长度 __int128 l2;//棒的长度的平方,棒的长度的平方。__int128防止超过数据范围 scanf("%d%lld", &n, &l); l2 = l * l; ll x, y; for (int i = 0; i < n; i++) { scanf("%lld%lld%d", &x, &y, &p[i].z); p[i].id = i; p[i].r = x * x + y * y;//半径的平方 p[i].angle = atan2(x, y);//算角度。atan2可以处理为0的情况,注意是顺时针从y轴正方向开始 if (p[i].angle < 0)//把第二、三象限的角度转过来 p[i].angle = pi2 + p[i].angle; } sort(p, p + n, [](const point &a, const point &b) -> bool { return a.r < b.r; });//按半径排序 priority_queue<point, vector<point>, greater<>> q; // 按角度排序的优先队列 int pos; for (pos = 0; pos < n && p[pos].r <= l2; pos++) { q.push(p[pos]); }
#include<bits/stdc++.h> #define pay second #define num first usingnamespace std; using ll = longlong; #define int long long // 十年oi一场空,不开 long long见祖宗 typedef pair<int, int> pp;
signedmain() { ios::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr); // 正式比赛不要用这两行,用scanf和printf int n, s; cin >> n >> s; vector<pair<int, int>> arr(n); for (int i = 0; i < n; i++) { cin >> arr[i].pay >> arr[i].num; } sort(arr.begin(), arr.end()); int single_paid = 0, sum = 0, i; for (i = n - 1; i >= 0; i--) { single_paid += arr[i].pay; if (single_paid >= s) // 从第i个开始往前,集体训练更便宜,使用集体训练 { break; } } int c; if (i == -1) // 全都是单独训练便宜 { i = 0; c = 0; } else { c = arr[i].num; } sum = c * s; for (int j = i; j < n; j++) { sum += arr[j].pay * (arr[j].num - c); } cout << sum << endl; return0; }