玄学错误......

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

#include<iostream> #include<stdio.h> #include<cmath> using namespace std; int n,i,j,sum,ans,ai,bi,aii,bii; char a,b; string st; int main() { cin>>n; cin>>st; ans=2; for (i=1; i<st.size(); i++) { a=st[i]; ai=i; b=st[i-1]; bi=i-1; sum=2; aii=ai; bii=bi; while (true) { bi--; if (bii==bi) break; if (bi==0) bi=st.size()-1; if (st[bi]!='w') { if (st[bi]!=b && b!='w') break; if (st[bi]!=b && b=='w') b=st[bi]; } sum++; } while (true) { ai++; if (aii==ai) break; if (ai==st.size()) ai=0; if (st[ai]!='w') { if (st[ai]!=a && a!='w') break; if (st[ai]!=a && a=='w') a=st[ai]; } sum++; } ans=max(ans,sum); } cout<<ans<<endl; }
by Blue_Sky @ 2018-08-26 16:40:47


```cpp #include<iostream> #include<stdio.h> #include<cmath> using namespace std; int n,i,j,sum,ans,ai,bi,aii,bii; char a,b; string st; int main() { cin>>n; cin>>st; ans=2; for (i=1; i<st.size(); i++) { a=st[i]; ai=i; b=st[i-1]; bi=i-1; sum=2; aii=ai; bii=bi; while (true) { bi--; if (bii==bi) break; if (bi==0) bi=st.size()-1; if (st[bi]!='w') { if (st[bi]!=b && b!='w') break; if (st[bi]!=b && b=='w') b=st[bi]; } sum++; } while (true) { ai++; if (aii==ai) break; if (ai==st.size()) ai=0; if (st[ai]!='w') { if (st[ai]!=a && a!='w') break; if (st[ai]!=a && a=='w') a=st[ai]; } sum++; } ans=max(ans,sum); } cout<<ans<<endl; } ```
by CHHC @ 2018-08-26 16:43:48


|