目录
Codeforces Round 905 (Div. 3)
A. Morning
模拟光标移动即可
void solve(){
string ss;
cin >> ss;
char ch = '1';
int ans = 0;
for(auto c : ss){
if(c != ch){
int x = c, y = ch;
if(c == '0') x = '9' + 1;
if(ch == '0') y = '9' + 1;
ans += abs(x - y);
ch = c;
}
++ ans;
}
cout << ans << '\n';
return ;
}
B. Chemistry
先统计每种字符出现的次数,再统计字符出现次数为奇数的个数 \(cnt\),如果 $cnt \le k + 1 $ 则可以满足要求,反之不行
void solve(){
int n, k;
string ss;
cin >> n >> k >> ss;
vector<int> cnt(26, 0);
for(auto c : ss){
++ cnt[c - 'a'];
}
int shu[2] = {0, 0};
for(int i = 0; i < 26; ++ i)
if(cnt[i]) ++ shu[cnt[i] % 2];
if(k >= shu[1] - 1) cout << "YES\n";
else cout << "NO\n";
return ;
}
C. Raspberries
分类讨论
k = 2,3,5 时,只有给定的数变成其的倍数才行,记录改变所需最小值即
k = 4 需特判,k = 4 = 2 * 2,我们
void solve(){
int n, ans = inf, k, a, shu[2] = {0, 0};
cin >> n >> k;
for(int i = 0; i < n; ++ i){
cin >> a;
ans = min(ans, (k - a % k) % k);
++ shu[a % 2];
}
if(k == 4){
if(shu[1] >= 2){
int t = 2 - min(2, shu[0]);
ans = min(ans, t);
}else if(shu[1] == 1){
if(shu[0] > 1) ans = 0;
else if(shu[0] == 1) ans = min(ans, 1);
else ans = min(ans, 3);
}else{
if(shu[0] >= 2) ans = 0;
}
}
cout << ans << '\n';
return ;
}
标签:cnt,shu,905,int,++,Codeforces,ss,ans,div.3
From: https://www.cnblogs.com/Qiansui/p/17782112.html