题号:1203
并不知道为什么AC,本来45分瞎改了改AC的。。。这破题也是神烦……
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 | #include<iostream> #include<algorithm> #include<string> #include<utility> #include<queue> #include<cstdlib> #include<cstring> #include<map> using namespace std; int n; string s; char search(int start, int ptr){ for (int i = ptr; i - start +1 <= n; i++){ if (s[i] != 'w')return s[i]; } return 'w'; } int run(int start,char c, char a){ int tmax = 0; bool flag = false; int ptr = start; char cur; if (s[start] == a)return 0; while (1){ if (!flag){ if (s[ptr] == c || s[ptr] == 'w')tmax++; else { flag = true; tmax++; cur = search(start, ptr); //就这里,我觉得reference 2应该是ptr+1才对。。 } } else{ if (s[ptr] == cur || s[ptr] == 'w')tmax++; else break; } ptr++; if (ptr - start >= n){ break; } } return tmax; } int main(){ ios::sync_with_stdio(false); cin >> n >> s; s.append(s); int m = 0; for (int i = 0; i <= n; i++){ int t = run(i, 'b', 'r'); if (t>m)m = t; t = run(i, 'r', 'b'); if (t > m)m = t; } cout << m; } |