Codeforces Round 1022 (Div. 2)
link: https://codeforces.com/contest/2108
D题目前通过才一两百, 题目也大概都读了下, 感觉不太有必要看了, 来总结一下。。。
这场总的来说糖丸了, B 只需要讨论就好, C 代码思路都特别简单。 但是这两题加起来 WA 了三次。
其中两次都是很不应该错的地方, 再怎么也不该错的, 而且也耽误时间。 总之还是得多写题, 才能少错, 才能速度更快。
A
这个 A 给我紧张到了, 很看了一会才 AC, 猜了一下。 我猜的是最大的值是数组
// Date: 2025-05-01
// Time: 22:36:38
void ChatGptDeepSeek()
{
int n;
cin >> n;
/*
0
2 * (pi-pj)
*/
int mx = 0;
for(int i = 1, j = n; i <= n; i++, j--)
mx += abs(j - i);
cout << mx / 2 + 1 << '\n';
}B
其实就分类讨论就行, 我第二次 WA 是因为判断
也是耽误了 8 分钟和扣了50。一定得细心一点吧, 这种分类讨论的题, 提交之前, 一定再把每种情况去简单想一下。
否则, 我们看一下
否则, 如果
然后到这里, 答案应该就分类完了。
// Date: 2025-05-01
// Time: 22:56:16
void ChatGptDeepSeek()
{
int n, x;
cin >> n >> x;
int cnt = 0, tmp = x;
while (tmp) {
cnt += tmp & 1;
tmp >>= 1;
}
// cout <<cnt <<'\n';
if (x == 0) {
if (n == 1)
cout << "-1\n";
else{
if(n % 2 == 0) cout << n << '\n';
else{// 1 1 1 1, 2, 3
cout << n + 3 <<'\n';
}
}
return;
}
if (cnt < n) {
if ((n - cnt) & 1) {
if (cnt == 1) {
// 1 2 3,
if(x == 1){
//2 3, 其他全取1
cout << 3 + n <<'\n';
}else{
//x+1 1
cout << n + x << '\n';
}
}// 8, 9 ^ 1
else{
cout << x + n - cnt + 1 << '\n';
}
}else {
cout << x + n - cnt << '\n';
}
}else{
cout << x <<'\n';
}
}C
感觉确实不一定比 B 难, 排个序然后顺着弄就行。 可能还是读题比较难。。。
// Date: 2025-05-01
// Time: 23:35:57
void ChatGptDeepSeek()
{
int n;
cin >> n;
vi a(n + 1);
for(int i = 1; i <= n; i++)
cin >> a[i];
int now = a[1], cnt = 0;
vc<array<int, 3>> info;
for(int i = 1; i <= n; i++){
if(a[i] == now)
cnt++;
else{
info.push_back({now, i - cnt, i - 1});
now = a[i], cnt = 1;
}
}
info.push_back({now, n - cnt + 1, n});
sort(all(info), greater<>());
vc<bool> vis(n + 1);
int ans = 0;
for(auto [val, l ,r] : info){
// cerr << val << " " << l << " " << r <<'\n';
if(l && vis[l - 1]){
vis[r] = true;
}else if(r < n && vis[r + 1]){
vis[l] = true;
}else{
vis[l] = vis[r] = true;
ans++;
}
}
cout << ans << '\n';
}