题意:给定一个长度为n的灯泡的状态序列,经过每个灯泡时,都要开关一下(开变关,关变开),问能否在回到终点的条件下关掉所有的灯。
思路:没出现一个为1的灯,都需要走奇数步来关掉它,而灯的总数为奇数的时候才能走奇数步,偶数同理。那么总数和1的个数同奇同偶时为YES。
code:
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <set>
#include <queue>
#include <map>
using namespace std;#define ft(i,s,t) for (int i=s;i<=t;i++)
#define cls(a,c) memset(a,c,sizeof(a))
typedef long long ll;
const int N=1000006;
const int M=105;int main()
{int T;scanf("%d",&T);while (T--){int s=0,t,n;scanf("%d",&n);ft(i,1,n) {scanf("%d",&t);if (t==1) s++;}if (n%2&&s%2) puts("YES");else if (n%2==0&&s%2==0) puts("YES");else puts("NO");}
}