2022ICPC济南 - E K M
2022 International Collegiate Programming Contest, Jinan Site
cf 传送门
E. Identical Parity
无论 k 怎么给定,k 个数里面奇数个数要么和偶数相等,要么奇数比偶数多一个(因为总体的奇数个数可能比偶数个数多一个),此时再利用余数去补足即可
少点感觉是怎么回事。。。
void solve(){
int n, k;
cin >> n >> k;
if(n == 1) cout << "Yes\n";
else if(k % 2 == 0) cout << "Yes\n";
else{
int cnta = (n + 1) / 2, cntb = n / 2;
int numa = k / 2 + 1, numb = k / 2;
int x = n / k, r = n % k;
int lefta = cnta - x * numa, leftb = cntb - x * numb;
if(lefta >= 0 && leftb >= 0 && lefta + leftb == r){
if(lefta <= numa && leftb <= numb){
cout << "Yes\n";
return ;
}
}
cout << "No\n";
}
return ;
}
K. Stack Sort
从前往后遍历标记每个数,如果当前数 + 1 出现过则跟到前面的栈里面,没出现过就新开一个栈
void solve(){
int n, a, ans = 0;
cin >> n;
vector<bool> vis(n + 2, false);
for(int i = 0; i < n; ++ i){
cin >> a;
if(!vis[a + 1]) ++ ans;
vis[a] = true;
}
cout << ans << '\n';
return ;
}
M. Best Carry Player
模拟进位即可,记得数组开大点就行
void solve(){
int n;
cin >> n;
vector<int> d(100, 0);
for(int i = 0; i < n; ++ i){
int a, c = 0;
cin >> a;
while(a){
d[c] += a % 10;
a /= 10;
++ c;
}
}
ll ans = 0;
for(int i = 0; i < 99; ++ i){
ans += d[i] / 10;
d[i + 1] += d[i] / 10;
}
cout << ans << '\n';
return ;
}