pku1063 Flip and Shift

#include <iostream> using namespace std; int pos[31]; int m, n, loop; int main() { int t, i, j, k, sum1, sum2, odd, even; cin >> t; while (t--) { cin >> loop; for (m=0, n=0, i=0; i<loop; i++) { cin >> k; if (k == 1) pos[n++] = i; } m = loop - n; if (n<=1 || m<=1 || loop%2==1) { cout << "YES" << endl; continue; } k = pos[0]; for (even=0, odd=0, i=0; i<n; i++) { pos[i] -= k; pos[i] = abs(pos[i]); if (pos[i]%2 == 0) even++; else odd++; } if (even==odd || even==odd+1 || odd==even+1) cout << "YES" << endl; else cout << "NO" << endl; } }

你可能感兴趣的:(pku1063 Flip and Shift)