22分求助!悬关!!!

P1203 [USACO1.1] 坏掉的项链 Broken Necklace

```cpp #include<bits/stdc++.h> using namespace std; int pd(char c){ if(c=='w'){ return 0; } if(c=='r'){ return 1; } if(c=='b'){ return 2; } } int sl(string &s,int i,int d,int n){ int num=0,zt=0; while(i>=0&&i<n*2){ zt=zt|pd(s[i]); if(zt==3){ break; } num++; i+=d; } return num; } int main(){ string s; int n,big=0,zb,yb; cin>>n>>s; s+=s; for(int i=0;i<n*2;i++){ zb=sl(s,i-1,-1,n); yb=sl(s,i,1,n); big=max(big,zb+yb); } cout<<min(big,n); return 0; } ```
by Chrome_Dino @ 2024-04-28 21:35:56


谢谢,已关
by 0xllllllllllf @ 2024-05-14 18:19:48


|