目录
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 ;
}
标签:奇数,int,个数,cin,偶数,vis,2022ICPC,济南
From: https://www.cnblogs.com/Qiansui/p/17810922.html