N bulbs
Accepts: 275
Submissions: 1237
Time Limit: 10000/5000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
思路:
对于偶数个0,能够愉快的通过,当是奇数个时0001 -->0010而且人在1的位置,于是又从后面开始数0,直至判断最后一个1后还有多少个0即可
#include <iostream> #include <cstdio> #include <cstdlib> #include <functional> #include <cmath> #include <cstring> #include <algorithm> using namespace std; const int maxn = 1000000; int a[maxn]; int main() { int T; scanf("%d",&T); while(T--) { int n; scanf("%d",&n); for(int i= 0; i < n; i++) { scanf("%d",&a[i]); } int num = 0; int flag = 1; for(int i = 0; i < n; i++) { if(a[i] != 1) num++; if(a[i] == 1) { if(num % 2 ) { num = 1; } else num = 0; } if(i == n-1) { if(num % 2) flag = 0; else flag = 1; } } if(flag == 0) printf("NO "); else printf("YES "); } return 0; }