CodeForces Round 525
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CodeForces Round 525相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/%e5%ba%8f%e5%88%97' title='搴忓垪'>搴忓垪
unsigned cout its txt tor 鍒ゆ柇 ace 骞朵笖A:Ehab and another construction problem
#include<bits/stdc++.h> using namespace std; #define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout); #define LL long long #define ULL unsigned LL #define fi first #define se second #define pb push_back #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define lch(x) tr[x].son[0] #define rch(x) tr[x].son[1] #define max3(a,b,c) max(a,max(b,c)) #define min3(a,b,c) min(a,min(b,c)) typedef pair<int,int> pll; const int inf = 0x3f3f3f3f; const int _inf = 0xc0c0c0c0; const LL INF = 0x3f3f3f3f3f3f3f3f; const LL _INF = 0xc0c0c0c0c0c0c0c0; const LL mod = (int)1e9+7; const int N = 1e5 + 100; int main(){ int x; scanf("%d", &x); for(int i = 1; i <= x; ++i) for(int j = 1; j <= x; ++j){ if(i%j == 0 && i*j > x && i/j < x){ cout << i << 鈥?/span> 鈥?/span> << j << endl; return 0; } } cout << -1 << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout); #define LL long long #define ULL unsigned LL #define fi first #define se second #define pb push_back #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define lch(x) tr[x].son[0] #define rch(x) tr[x].son[1] #define max3(a,b,c) max(a,max(b,c)) #define min3(a,b,c) min(a,min(b,c)) typedef pair<int,int> pll; const int inf = 0x3f3f3f3f; const int _inf = 0xc0c0c0c0; const LL INF = 0x3f3f3f3f3f3f3f3f; const LL _INF = 0xc0c0c0c0c0c0c0c0; const LL mod = (int)1e9+7; const int N = 1e5 + 100; int a[N]; int main(){ int n, m; scanf("%d%d", &n, &m); for(int i = 1; i <= n; ++i) scanf("%d", &a[i]); sort(a+1, a+1+n); int val = 0, b = 1; for(int i = 1; i <= m; ++i){ while(b <= n && val >= a[b]) ++b; if(b > n) puts("0"); else { printf("%d ", a[b]-val); val = a[b]; } } return 0; }
棰樻剰锛氳姹傛瀯閫犱竴涓弗鏍奸€掑搴忓垪銆?/p>
棰樿В锛氫竴鍏辨渶澶氭湁n+1娆℃搷浣滐紝鎵€浠ユ垜浠粠鍚庡線鍓嶆瘡娆℃瀯閫犵i涓暟锛?鎶婁粬鏋勯€犳垚瀵?n涔嬪悗鐨勪綑鏁颁负锛坕-1)銆?鏈€鍚庡啀瀵规暣涓暟鍒?n灏卞ソ浜嗐€?/p>
浠g爜锛?/p>
Copy #include<bits/stdc++.h> using namespace std; #define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout); #define LL long long #define ULL unsigned LL #define fi first #define se second #define pb push_back #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define lch(x) tr[x].son[0] #define rch(x) tr[x].son[1] #define max3(a,b,c) max(a,max(b,c)) #define min3(a,b,c) min(a,min(b,c)) typedef pair<int,int> pll; const int inf = 0x3f3f3f3f; const int _inf = 0xc0c0c0c0; const LL INF = 0x3f3f3f3f3f3f3f3f; const LL _INF = 0xc0c0c0c0c0c0c0c0; const LL mod = (int)1e9+7; const int N = 1e5 + 100; int n; int a[N]; struct Node{ int op, l, r; }; vector<Node> ans; int main(){ scanf("%d", &n); for(int i = 1; i <= n; ++i) scanf("%d", &a[i]); int val = 0; for(int i = n; i >= 1; --i){ a[i] += val; int t = a[i]%n; if(t == i-1) continue; t = (n+(i-1) - t); val += t; ans.pb({1, i, t}); } ans.pb({2, n, n}); printf("%d ", ans.size()); for(auto it : ans){ printf("%d %d %d ", it.op, it.l, it.r); } return 0; }
D锛?a href="https://codeforces.com/contest/1088/problem/D">Ehab and another another xor problem
浜や簰棰樸€?/p>
棰樿В锛?/p>
鎴戜滑鍙互閫氳繃杈撳嚭 0 0 鏉ュ垽鏂?a 鍜?b鐨勫ぇ灏忋€?/p>
鐒跺悗鎴戜滑鑰冭檻ab鐨勪簩杩涘埗銆?/p>
浠庨珮浣嶅線鍦颁綅鏋氫妇
銆€ 灏嗙i浣峖1涔嬪悗锛?濡傛灉 a鍜宐鐨勪害鎴栧悗鐨勫ぇ灏忔病鍙戠敓鏀瑰彉锛?鍒欒鏄庣i浣嶆槸涓€鏍?1鐮佺殑銆?/p>
灏嗙i浣峖1涔嬪悗锛?濡傛灉 a鍜宐鐨勪害鎴栧悗鐨勫ぇ灏忓彂鐢熶簡鍙樺寲锛?閭d箞灏辫鏄庣i浣嶇殑01鐮佹槸涓嶄竴鏍风殑锛屽苟涓斿師鏉ュぇ鐨勯偅涓暟绗琲浣嶆槸1锛岃褰曚笅杩欎竴浣嶇殑鍙樺寲锛?鐒跺悗鍓嶉潰杩欎竴浣嶈€冭檻杩涘幓涔嬪悗锛岄噸鏂拌闂帴鏉ヤ笅鐨勫墿涓嬩綅鏁扮殑ab澶у皬銆?/p>
缁忚繃涓婇潰鐨勬搷浣滐紝鎴戜滑灏辩‘瀹氫簡涓嶄竴鏍风殑浣嶇疆鐨勪俊鎭紝鐒跺悗鍦ㄥ幓鎵惧悓鎰忎綅缃笂鐨勪俊鎭氨濂戒簡銆?/p>
浠g爜锛?/p>
#include<bits/stdc++.h> using namespace std; #define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout); #define LL long long #define ULL unsigned LL #define fi first #define se second #define pb push_back #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define lch(x) tr[x].son[0] #define rch(x) tr[x].son[1] #define max3(a,b,c) max(a,max(b,c)) #define min3(a,b,c) min(a,min(b,c)) typedef pair<int,int> pll; const int inf = 0x3f3f3f3f; const int _inf = 0xc0c0c0c0; const LL INF = 0x3f3f3f3f3f3f3f3f; const LL _INF = 0xc0c0c0c0c0c0c0c0; const LL mod = (int)1e9+7; const int N = 1e5 + 100; int t, val, f = 0; int ans1, ans2; int vis[N]; int xx = 10, yy = 5; int gg(int x, int y){ x ^= xx; y ^= yy; if(x > y) return 1; if(x ==y) return 0; return -1; } int main(){ printf("? 0 0 "); fflush(stdout); scanf("%d", &t); f = t; for(int i = 29; i >= 0 && f != 0; --i){ int o1 = 1 << i; int o2 = o1 ^ val; printf("? %d %d ", o1, o2); fflush(stdout); scanf("%d", &t); if(f == 1){ if(t == -1){ val ^= o1; ans1 ^= o1; vis[i] = 1; printf("? %d %d ", 0, val); fflush(stdout); scanf("%d", &f); } } else if(f == -1){ if(t == 1){ val ^= o1; ans2 ^= o1; vis[i] = 1; printf("? %d %d ", 0, val); fflush(stdout); scanf("%d", &f); } } } for(int i = 29; i >= 0; --i){ if(vis[i]) continue; int o1 = 1 << i; int o2 = val; printf("? %d %d ", o1, o2); fflush(stdout); scanf("%d", &t); if(t == -1){ ans1 ^= o1; ans2 ^= o1; } } printf("! %d %d ", ans1, ans2); fflush(stdout); return 0; }
E锛?a href="https://codeforces.com/contest/1088/problem/E">Ehab and a component choosing problem
棰樻剰锛氬湪涓€棰楁爲涓婏紝姣忎釜鐐归兘鏈夋潈鍊硷紝 浣犲彲浠ラ€夋嫨k涓仈閫氬潡锛?浣垮緱 鎵€鏈夐€夊緱鐨勭偣鐨勫拰/k鐨勫€兼渶澶э紝 鍦ㄤ繚璇佸€兼渶澶х殑鍓嶆彁涓嬶紝 k鏈€澶с€?/p>
棰樿В锛氭墍鏈夐€夋嫨鐨勭偣/k 銆?鎴戜滑鑰冭檻杩欎釜涓滆タ锛?鑲畾灏辨槸 杩檏涓潡鐨勫€奸兘鏄竴鏍风殑銆傚苟涓旀垜浠渶瑕佷繚璇佽繖鍊兼槸鍥句腑鏈€澶х殑鍊笺€?/p>
閭d箞鎴戜滑鍙互閫氳繃dfs鎵惧埌杩欎釜鍊兼渶澶ф槸澶氬皯銆?/p>
鐒跺悗鍦ㄩ€氳繃dfs鍘籧heck鏈€澶氭湁澶氬皯涓繖绉嶅潡銆?/p>
浠g爜锛?/p>
#include<bits/stdc++.h> using namespace std; #define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout); #define LL long long #define ULL unsigned LL #define fi first #define se second #define pb push_back #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define lch(x) tr[x].son[0] #define rch(x) tr[x].son[1] #define max3(a,b,c) max(a,max(b,c)) #define min3(a,b,c) min(a,min(b,c)) typedef pair<int,int> pll; const int inf = 0x3f3f3f3f; const int _inf = 0xc0c0c0c0; const LL INF = 0x3f3f3f3f3f3f3f3f; const LL _INF = 0xc0c0c0c0c0c0c0c0; const LL mod = (int)1e9+7; const int N = 3e5 + 100; int a[N]; vector<int> vc[N]; LL ans = _INF; LL dfs1(int o, int u){ LL val = a[u]; for(int v : vc[u]){ if(v == o) continue; val += max(0ll, dfs1(u,v)); } ans = max(ans, val); return val; } int k = 0; LL dfs2(int o, int u){ LL val = a[u]; for(int v : vc[u]){ if(v == o) continue; val += max(0ll, dfs2(u,v)); } if(val == ans) ++k, val = 0; return val; } int main(){ int n; scanf("%d", &n); for(int i = 1; i <= n; ++i) scanf("%d", &a[i]); for(int i = 1,u,v; i < n; ++i){ scanf("%d%d", &u, &v); vc[u].pb(v); vc[v].pb(u); } dfs1(0,1); dfs2(0,1); cout << 1ll * ans * k << 鈥?/span> 鈥?/span> << k << endl; return 0; }
F锛?a href="https://codeforces.com/contest/1088/problem/F">Ehab and a weird weight formula
棰樻剰锛氱粰瀹氫竴妫垫爲锛屾瘡涓妭鐐规湁鏉冨€硷紝骞朵笖鍙湁鎵€鏈夋潈鍊间腑锛屾渶灏忓€肩殑鐐瑰彧鏈変竴涓€?骞朵笖闄や簡鏈€灏忓€肩殑閭d釜鐐癸紝 鍏朵粬鐨勭偣杩炲悜鐨勭偣涓紝涓€瀹氭湁涓€涓偣鐨?v[u] < v[i]銆傜幇鍦ㄨ姹備綘閲嶆瀯杩欐5鏍戯紝鐒跺悗浣垮緱
1. 姣忎釜鐐圭殑搴︽暟 * v[i] + 2. 瀵逛笌鏂板浘鐨勬瘡鏉¤竟鐨剓u锛寁} -> log(dis(u,v)) * min锛坅[u], a[v]) 鎵€鏈夊拰鏈€灏忋€?/p>
棰樿В锛?/p>
鎴戜滑闇€瑕佽瘉鏄庝竴涓笢瑗匡紝鍗充粠鏉冨€兼渶灏忕殑閭d釜鐐瑰嚭鍙戜箣鍚庯紝 瀵逛簬鏌愭潯閾炬潵璇达紝娣卞害瓒婂ぇ鐨勭偣鐨勬潈鍊间竴瀹氬ぇ浜庢繁搴﹀皬鐨勭偣銆?/p>
鍋囧瀛樺湪涓€鏉¢摼锛?A -> B -> C -> D
A鏄叾涓渶灏忕殑鐐广€?nbsp;
鎴戜滑鍋囪 v[B] > v[A], v[C] < v[B]
鍥犱负闇€瑕佹弧瓒抽鐩粰瀹氱殑閭d釜鏉′欢锛?鎵€浠?v[D] < v[C]銆?/p>
閭d箞瀵逛簬D鏉ヨ涔熼渶瑕佸瓨鍦ㄤ竴涓偣鐨勫€兼槸灏忎簬D鐨勶紝 浣嗘槸涓嶅瓨鍦ㄨ繖绉嶇偣锛?鎵€浠ヨ繖涓亣璁炬槸鐭涚浘鐨勩€?/p>
鎴戜滑鍙互绠€鍗曡瘉寰?浠庢渶灏忕偣鍑哄彂锛?浠栫殑鍊兼槸閫掑鐨勩€?/p>
鐒跺悗鎴戜滑鍊嶅璺戜竴涓嬫瘡涓偣鐨勬瘡灞傜鍏堟槸浠€涔堝氨濂戒簡銆?/p>
浠g爜锛?/p>
#include<bits/stdc++.h> using namespace std; #define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout); #define LL long long #define ULL unsigned LL #define fi first #define se second #define pb push_back #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define lch(x) tr[x].son[0] #define rch(x) tr[x].son[1] #define max3(a,b,c) max(a,max(b,c)) #define min3(a,b,c) min(a,min(b,c)) typedef pair<int,int> pll; const int inf = 0x3f3f3f3f; const int _inf = 0xc0c0c0c0; const LL INF = 0x3f3f3f3f3f3f3f3f; const LL _INF = 0xc0c0c0c0c0c0c0c0; const LL mod = (int)1e9+7; const int N = 5e5 + 100; int v[N]; LL ans = 0; int anc[N][20]; vector<int> vc[N]; void dfs(int o, int u){ anc[u][0] = o; for(int i = 1; i < 20; ++i) anc[u][i] = anc[anc[u][i-1]][i-1]; if(o){ LL tmp = INF; for(int i = 0; i < 20; ++i){ tmp = min(tmp, 1ll*v[anc[u][i]]*(i+1)); } tmp += v[u]; ans += tmp; } for(int v : vc[u]){ if(v == o) continue; dfs(u, v); } } int main(){ int n; int rt = 1; scanf("%d", &n); for(int i = 1; i <= n; ++i){ scanf("%d", &v[i]); if(v[i] <= v[rt]) rt = i; } for(int i = 1,u,v; i < n; ++i){ scanf("%d%d", &u, &v); vc[u].pb(v); vc[v].pb(u); } v[0] = v[rt]; // cout << "bug" << endl; dfs(0, rt); printf("%lld ", ans); return 0; }
以上是关于CodeForces Round 525的主要内容,如果未能解决你的问题,请参考以下文章
Codeforces Round #525 (Div. 2)
Codeforces Round #525 (Div. 2)A. Ehab and another construction problem
[Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3)][C. Playing Piano](代码片段
Codeforces Round #525 E - Ehab and a component choosing problem