Beautiful Palindromes题目链接Problem - E - Codeforces题目描述思路可以发现n大于等于3并且每次向尾巴添加3个不同的数即可添加的第一个数不要和原数组最后一个数相等代码#include bits/stdc.h using namespace std; #define x first #define y second #define int long long #define endl \n typedef pairint, int PII; const int mod 1e9 7; int dx[4] {-1, 0, 1, 0}; int dy[4] {0, 1, 0, -1}; void solve() { int n, k; cin n k; vectorint a(n), cnt(n 1); for(int i 0; i n; i ) { cin a[i]; cnt[a[i]] ; } int x -1; for(int i 1; i n; i ) if(cnt[i] 0) { x i; break; } if(x -1) { for(int i 0; i k; i ) cout a[n - 3 (i % 3)] \n[i k - 1]; } else { int y -1; for(int i 1; i n; i ) if(i ! x i ! a[n - 1]) { y i; break; } vectorint ans{x, y, a[n - 1]}; for(int i 0; i k; i ) cout ans[i % 3] \n[i k - 1]; } } int32_t main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); int T 1; cin T; while(T -- ) { solve(); } return 0; }Arcology On Permafrost题目链接Problem - D - Codeforces题目描述思路题目数据范围是m * k n并且每个相同的数字相隔的距离必须大于等于k不然就会被删掉然后f(a) n - m *k最后可以构造出来mex max(k, n / (m 1))代码#include bits/stdc.h using namespace std; #define x first #define y second #define int long long #define endl \n typedef pairint, int PII; const int mod 1e9 7; int dx[4] {-1, 0, 1, 0}; int dy[4] {0, 1, 0, -1}; void solve() { int n, m, k; cin n m k; int mex max(n / (m 1), k); vectorint a(mex); iota(a.begin(), a.end(), 0); for(int i 0; i n; i ) cout a[i % mex] \n[i n - 1]; } int32_t main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); int T 1; cin T; while(T -- ) { solve(); } return 0; }Trulimero Trulicina题目链接Problem - F - Codeforces题目描述思路打表发现当m不为k的倍数时一直1....k从第一行第一列一直输到第n行第n列一定是满足的因为会造成错位使得邻接的一定不同当m为k的倍数时由于正常的输出不会造成错位我们考虑手动造成错位在行数位奇数时考虑将m / k组的数字以2 1 .... k这种形式输出代码#include bits/stdc.h using namespace std; #define x first #define y second #define int long long #define endl \n typedef pairint, int PII; const int mod 1e9 7; int dx[4] {-1, 0, 1, 0}; int dy[4] {0, 1, 0, -1}; void solve() { int n, m, k; cin n m k; if(m % k ! 0) { int cnt 0; for(int i 1; i n; i ) for(int j 1; j m; j ) cout ( cnt - 1) % k 1 \n[j m]; } else { for(int i 1; i n; i ) { if(i % 2) { for(int j 1; j k - 1 m; j k) { cout k ; for(int p 1; p k - 1; p ) cout p ; } } else { int cnt 0; for(int j 1; j m; j ) cout ( cnt - 1) % k 1 ; } cout endl; } } } int32_t main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); int T 1; cin T; while(T -- ) { solve(); } return 0; }The Morning Star题目链接Problem - F - CodeforcesProblem - G - CodeforcesProblem - F - Codeforces题目描述思路每个点每个点的去比较一定不妥考虑给每个点按行列所在直线分类再用A(n, 2)O(1)的来进行计算大概时间复杂度是O(n)直线可以用xyx-y来分类因为题目的斜率要么是1要么是-1按照直线的定义有x ( -) y c;代码#include bits/stdc.h using namespace std; #define x first #define y second #define int long long #define endl \n typedef pairint, int PII; const int mod 1e9 7; int dx[4] {-1, 0, 1, 0}; int dy[4] {0, 1, 0, -1}; void solve() { int n; cin n; mapint, int X; mapint, int Y; mapint, int diag1; mapint, int diag2; for(int i 1; i n; i ) { int x, y; cin x y; X[x] ; Y[y] ; diag1[x - y] ; diag2[x y] ; } int ans 0; for(auto t : X) ans t.y * (t.y - 1); for(auto t : Y) ans t.y * (t.y - 1); for(auto t : diag1) ans t.y * (t.y - 1); for(auto t : diag2) ans t.y * (t.y - 1); cout ans endl; } int32_t main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); int T 1; cin T; while(T -- ) { solve(); } return 0; }Strong Vertices题目链接Problem - D - Codeforces题目描述思路按照题目意思将每个点的权值求出来最大权值的那些点就是答案代码#include bits/stdc.h using namespace std; #define x first #define y second #define int long long #define endl \n typedef pairint, int PII; const int mod 1e9 7; int dx[4] {-1, 0, 1, 0}; int dy[4] {0, 1, 0, -1}; void solve() { int n; cin n; vectorint a(n 1), b(n 1); vectorPII c(n 1); for(int i 1; i n; i ) cin a[i]; for(int i 1; i n; i ) cin b[i]; for(int i 1; i n; i ) { c[i].x a[i] - b[i]; c[i].y i; } sort(c.begin() 1, c.end(), [](const PII A, const PII B) { return A.x B.x; }); vectorint ans; for(int i 1; i n; i ) if(c[i].x c[1].x) ans.push_back(c[i].y); sort(ans.begin(), ans.end()); cout ans.size() endl; for(int i 0; i ans.size(); i ) cout ans[i] \n[i ans.size() - 1]; } int32_t main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); int T 1; cin T; while(T -- ) { solve(); } return 0; }Power of Points题目链接Problem - E - Codeforces题目描述思路考虑排完序对选择a[i]这种情况进行分析令xi s; f(i) 维护前缀和后缀即可代码#include bits/stdc.h using namespace std; #define x first #define y second #define int long long #define endl \n typedef pairint, int PII; const int mod 1e9 7; int dx[4] {-1, 0, 1, 0}; int dy[4] {0, 1, 0, -1}; void solve() { int n; cin n; vectorint ans(n 1); vectorPII a(n 1); int sum 0; for(int i 1; i n; i ) { cin a[i].x; a[i].y i; sum a[i].x; } int s 0; sort(a.begin() 1, a.end()); for(int i 1; i n; i ) { s a[i].x; sum - a[i].x; ans[a[i].y] n a[i].x * (2 * i - n) - s sum; } for(int i 1; i n; i ) cout ans[i] \n[i n]; } int32_t main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); int T 1; cin T; while(T -- ) { solve(); } return 0; }Sum and Product题目链接Problem - F - Codeforces题目描述思路利用一元二次方程的公式有x1 x2 -b, x1 * x2 c, D b * b - 4 * a * c, x1, x2 -b (-)sqrt(D) 可以求出两个根记录每个ai出现的次数当没有根时则没有解只有一个根时则有C(cnt[x1], 2)个解两个时有cnt[x1] * cnt[x2]个代码#include bits/stdc.h using namespace std; #define x first #define y second #define int long long #define endl \n typedef pairint, int PII; const int mod 1e9 7; int dx[4] {-1, 0, 1, 0}; int dy[4] {0, 1, 0, -1}; mapint, int mp; int my_sqrt(int a) { int l 0, r 1e10; while(l r) { int mid (l r 1) 1; if(mid * mid a) l mid; else r mid - 1; } return l; } int get(int b, int c) { int D b * b - 4 * c; if(D 0) return 0; int sqrt_D my_sqrt(D); int x1 (b - sqrt_D) / 2; int x2 (b sqrt_D) / 2; if(x1 x2 ! b || x1 * x2 ! c) return 0; if(x1 x2) return mp[x1] * (mp[x1] - 1) / 2; else return mp[x1] * mp[x2]; } void solve() { int n; cin n; mp.clear(); for(int i 0, x; i n; i ) { cin x; mp[x] ; } int q; cin q; for(int i 1; i q; i ) { int b, c; cin b c; cout get(b, c) \n[i q]; } } int32_t main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); int T 1; cin T; while(T -- ) { solve(); } return 0; }