Codeforces Round #659 (Div. 2)
Posted goodvv
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #659 (Div. 2)相关的知识,希望对你有一定的参考价值。
A. Common Prefixes
代码:
#include<bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10; #define ll long long #define ios std::ios::sync_with_stdio(false) const ll INF(0x3f3f3f3f3f3f3f3fll); const int inf(0x3f3f3f3f); const int mod = 998244353; int a[maxn]; signed main() { ios,cin.tie(0); int t; cin >> t; while(t --){ int n; cin >> n; int sum = 0; for(int i = 1 ; i <= n ; i ++) cin >> a[i] , sum = (sum ^ a[i]); if(sum == 0){ cout << "DRAW "; } else{ int pos = 0; for(int i = 32 ; i >= 0 ; i --){ if((sum >> i) & 1){ pos = i; break; } } int cnt = 0; for(int i = 1 ; i <= n ; i ++){ if((a[i] >> pos) & 1){ cnt ++; } }/// if(cnt % 4 == 1 || n % 2 == 0){ cout << "WIN "; } else cout << "LOSE "; } } return 0; }
C. String Transformation 1
题意:
给字符串 A 和 B , 可以通过多少次以下操作 , 使得 A = B ,最小化操作数。
操作是 :
①.选定A字符串中一些相同的字符x (比如x = ‘a‘)
②.选一个 比x更大的字符y(比如x = ‘a‘ , 然后我选 y= ‘c‘)
③.把 选定A中的位置 全部换成 y(比如x = ‘a‘ , 然后 y = ‘c‘ , 然后把你选的所有位置的 ‘a‘ 都换成 ‘c‘)
想法:
代码:
#include<bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; #define ll long long #define ios std::ios::sync_with_stdio(false) const ll INF(0x3f3f3f3f3f3f3f3fll); const int inf(0x3f3f3f3f); #define int long long #define pb(a) push_back(a) #define debug(a) cout << "a : " << a << ‘ ‘ #define mp(a , b) make_pair(a ,b) string a , b; int change[100][100]; signed main() { ios; cin.tie(0); int t; cin >> t; while(t --){ memset(change , 0 , sizeof(change)); int n; cin >> n; cin >> a >> b; bool ok = true; for(int i = 0 ; i < n ; i ++){ if(a[i] > b[i]){ ok = false; break; } } if(!ok){ cout << "-1 "; continue; } int ans = 0; for(int i = 0 ; i < n ; i ++){ if(a[i] != b[i]){ change[a[i] - ‘a‘][b[i] - ‘a‘] ++; } } for(int i = 0 ; i <= 20 ; i ++){ int pos = -1; for(int j = i + 1 ; j <= 20 ; j ++){ if(change[i][j]){ pos = j; break; } } if(pos == -1)continue; for(int j = pos + 1 ; j <= 20 ; j ++){ if(change[i][j])change[pos][j] += change[i][j]; } ans ++; } cout << ans << ‘ ‘; } return 0; }
D. GameGame
题意:
给定一个数组a[] , 两个人初始数为0 , 轮流拿走数组中的一个数直到数组为空 , 把手里的数全部异或起来 ,谁的数更大就谁赢。(两个人都会选择当前对自己最优的拿法)
想法:
代码:
#include<bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10; #define ll long long #define ios std::ios::sync_with_stdio(false) int a[maxn]; signed main() { ios,cin.tie(0); int t; cin >> t; while(t --){ int n; cin >> n; int sum = 0; for(int i = 1 ; i <= n ; i ++) cin >> a[i] , sum = (sum ^ a[i]); if(sum == 0){ cout << "DRAW "; } else{ int pos = 0; for(int i = 32 ; i >= 0 ; i --){ if((sum >> i) & 1){ pos = i; break; } } int cnt = 0; for(int i = 1 ; i <= n ; i ++){ if((a[i] >> pos) & 1){ cnt ++; } }/// if(cnt % 4 == 1 || n % 2 == 0){ cout << "WIN "; } else cout << "LOSE "; } } return 0; }
以上是关于Codeforces Round #659 (Div. 2)的主要内容,如果未能解决你的问题,请参考以下文章
Codeforces Round #659 (Div. 2)
Codeforces Round #659 (Div. 1) 题解 (AB)
Codeforces Round #659 (Div. 2) A.Common Prefixes
Codeforces Round #659 (Div. 2) D GameGame
Codeforces Round #659 (Div. 2) B1. Koa and the Beach (Easy Version)