Codeforces Round 981 (Div. 3)
A.Sakurako and Kosuke
比较简单,手玩样例得出奇数K,偶数S
void solve(){
int n;
cin >> n;
if(n&1) cout << "Kosuke\n";
else cout << "Sakurako\n";
}
B.Sakurako and Water
不难发现只要遍历每一条主对角线,找到最大的需要+1的次数就能做出来,暴力判断即可
void solve(){
int n;
cin >> n;
for(int i = 1;i <= n;i++){
for(int j = 1;j <= n;j++){
cin >> a[i][j];
}
}
vector<int>sum(2*n);
for(int i = 1;i <= n;i++){
for(int j = 1;j <= n;j++){
sum[j - i + n] = std::max(-a[i][j],sum[j - i + n]); //如果在一条主对角线上则必然有j - i + n相等
}
}
int ans = 0;
for(auto t:sum){
ans += t;
}
cout << ans << '\n';
}
C.Sakurako's Field Trip
发现每次操作都是镜像,因此采用策略如果,则情况不会更劣。直接进行交换,最后计算得出最后的次数
void solve(){
int n;
cin >> n;
for(int i = 1;i <= n;i++){
cin >> a[i];
}
for(int i = 2;i <= n/2;i++){
if(a[i] == a[i - 1] || a[n - i + 2] == a[n - i + 1]) std::swap(a[n - i + 1],a[i]);
}
int ans = 0;
for(int i = 2;i <= n;i++){
if(a[i] == a[i - 1]) ans++;
}
cout << ans << '\n';
}
D. Kousuke's Assignment
前缀和为0就清空
void solve(){
int n = 0;
cin >> n;
std::map<int,bool>m;
int sum = 0,ans = 0;
m[0] = 1;
for(int i = 1,x;i <= n;i++){
cin >> x;
sum += x;
if(m[sum]){
ans++;
m.clear();
sum = 0;
}
m[sum] = 1;
}
cout << ans << '\n';
}