[CF1115 div2]

https://codeforces.com/contest/2252/problem/A A 题意可知,要使打出的伤害最高,出的牌要最多 我们考虑牌数最多的牌,因为少的牌能用来当多的牌的挡板,是一定能用掉的 所以我们考虑 最多牌的次数为m ,剩下的牌为 n-m 那最多的牌次数最多可以有 n-m+2 个 因为最末尾可以连放两个 于是有两种情况 1.m<=n-m+2 全部牌都能打出 2.m>n-m+2 多的牌太多了 多出的牌为 m - (n-m+2) 减去即可 代码 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 #include<bits/stdc++.h> using namespace std; typedef long long ll; void solve(){ int n; cin>>n; vector<int> a(n); int sum=0; int m=0; int t=0; vector<int> cnt(1005,0); for(int i=0;i<n;i++){ cin>>a[i]; sum+=a[i]; cnt[a[i]]++; if(cnt[a[i]]>m){ m=cnt[a[i]]; t=a[i]; } } if(m<=n-m+2){ cout<<sum<<'\n'; } else cout<<sum- t * (2*m -n -2)<<"\n"; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int ttt=1; cin>>ttt; while(ttt--){ solve(); } return 0; } https://codeforces.com/contest/2252/problem/B B 留下的字符串为交替,且我们删去的字符也是要交替的 设原来有 N个0 和 M个1 ,最终有 n个0 和 m个1 我们删去了d0 = N - n 个0 d1 = M-m 个 1 且 |d0 - d1| < = 1 代入得 | (N-M) - (n-m) | < =1 令 x = (N-M) y = (n-m) 且 y的值只能在 {-1,0,1} 三者取 因| x - y | <= 1 即 x>2 或 x<-2 无解 若有解 考虑最少操作次数,也就是保留的字符串要最长 理论最长肯定是 原先字符串 01块 的大小 我们可以算出这个 01 块 的 Y 值(即0和1的个数差) 因为 最终 y肯定在{-1,0,1} 三者取 我们遍历一遍 算出 Y 到 y 这个过程中要变的 长度即 min(|Y-y|) 保留的就是01块长度 len - |Y-y| 最后的操作次数就是原长减去保留 ...

August 7, 2026

[Edu CF193 div2]

https://codeforces.com/contest/2253/problem/A A 一张牌要战胜所有牌,容易想到 一段连续数字中 不可能 两两都保持整除关系 所以 数值小的肯定会被一个大于它的 打败 因此这张牌只能是最大的,且它在2- (x-1) 中都没有因子 那就是素数 即最大的为素数就存在 代码 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 #include<bits/stdc++.h> using namespace std; typedef long long ll; bool judge(int x){ for(int i=2;i*i<=x;i++){ if(x%i==0) return false; } return true; } void solve(){ int n; cin>>n; if(judge(n+1)) cout<<"YES\n"; else cout<<"NO\n"; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int ttt=1; cin>>ttt; while(ttt--){ solve(); } return 0; } https://codeforces.com/contest/2253/problem/B B 题意为保留最大交替块长度,在删除基础上 加了一个 相邻可交换的操作 观察到如果 有两块长度都 >=2 1122 交换一次为 1 2 1 2 贡献增加2 如果只有一块>=2 x1221x 只要x不与2 相同 交换为 x2121x 贡献增加1 先 求出原字符串 通过删除 能保留的最大串,再看 贡献能不能增加即可 ...

August 7, 2026

[CF2224C]

📝 核心思路 合法括号序列: ‘ ( ’ : 1 ‘ ) ’ : -1 在1,3,5奇数位置,前缀和要为奇数且大于0 在2,4,6偶数位置,前缀和要为偶数且大于等于0 且在末尾前缀和为0 由上述规律考虑: 我们考虑a和b的总前缀和 则奇数位置 前缀和为偶数 且大于等于2 偶数位置 前缀和为偶数 且大于等于0 且到末尾 要为0 考虑交换:如果当前位置不同,则让前缀和小的加上1,大的减去1 代码 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 #include<bits/stdc++.h> using namespace std; typedef long long ll; void solve(){ int n; cin>>n; string a,b; cin>>a; cin>>b; a=" "+a; b=" "+b; int sum=0; for(int i=1;i<=n;i++){ sum+=(a[i]=='(')?1:-1; sum+=(b[i]=='(')?1:-1; if( ( i&1 && sum<2 ) || ( !(i&1) && sum<0 ) ){ cout<<"NO"<<"\n"; return; } } if(sum!=0) cout<<"NO\n"; else cout<<"YES\n"; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int ttt=1; cin>>ttt; while(ttt--){ solve(); } //solve(); return 0; }

August 6, 2026

[CF2227D]

📝 核心思路 考虑回文串,单个数也是一个回文串 所以不管数字怎么排列,都能保证mex>=1,那我们只要考虑有没有mex大于1的回文串,那也就是考虑0的位置 因为有两个0,我们考虑三种情况: 1.0作为中心,双指针从两边出去,找回文串 因为有两个0 所以这有两种情况 2.两个0作为一对,首先保证两个0 之间的数是回文串,然后双指针从两边出去找回文串。 代码 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 #include<bits/stdc++.h> using namespace std; typedef long long ll; void solve(){ int n; cin>>n; vector<int> a(2*n); int pos1=-1; int pos2=-1; for(int i=0;i<2*n;i++){ cin>>a[i]; if(a[i]==0){ if(pos1==-1) pos1=i; else pos2=i; } } vector<bool> vis(n+1,false); vis[0]=true; int ans=1; // 0作为中心; int l=pos1-1,r=pos1+1; int mex=1; while(l>=0 && r<2*n && a[l]==a[r]){ vis[a[l]]=true; while(vis[mex]) mex++; l--; r++; } ans=max(ans,mex); vis.assign(n+1,false); l=pos2-1,r=pos2+1; mex=1; while(l>=0 && r<2*n && a[l]==a[r]){ vis[a[l]]=true; while(vis[mex]) mex++; l--; r++; } ans=max(ans,mex); // 0作为一对 vis.assign(n+1,false); mex-1; l=pos1+1,r=pos2-1; bool T=true; while(l<pos2 && r>pos1){ if(a[l]!=a[r]){ T=false; break; } vis[a[l]]=true; l++; r--; } if(T){ while(vis[mex]) mex++; l=pos1-1; r=pos2+1; while(l>=0 && r<2*n && a[l]==a[r]){ vis[a[l]]=true; while(vis[mex]) mex++; l--; r++; } } ans=max(ans,mex); cout<<ans<<"\n"; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int ttt=1; cin>>ttt; while(ttt--){ solve(); } //solve(); return 0; }

August 6, 2026