N bulbs
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 559 Accepted Submission(s): 298
in order to save electricity, you should turn off all the lights, but you're lazy.
coincidentally,a passing bear children paper(bear children paper means the naughty boy), who want to pass here from the first light bulb to the last one and leave.
he starts from the first light and just can get to the adjacent one at one step.
But after all,the bear children paper is just a bear children paper. after leaving a light bulb to the next one, he must touch the switch, which will change the status of the light.
your task is answer whether it's possible or not to finishing turning off all the lights, and make bear children paper also reach the last light bulb and then leave at the same time.
For each test case, there are 2 lines.
The first line of each test case contains 1 integers n.
In the following line contains a 01 sequence, 0 means off and 1 means on.
* 1≤T≤10
* 1≤N≤1000000
The i-th line should only contain "YES" or "NO" to answer if it's possible to finish.
Child's path is: 123234545
all switchs are touched twice except the first one.
#include<stdio.h>
#include<string.h>
#include<string>
#include<math.h>
#include<algorithm>
#define LL long long
#define PI atan(1.0)*4
#define DD doublea
#define MAX 1001000
#define mod 10007
using namespace std;
int light[MAX];
int main()
{
int n,m,j,i,s,t;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
s=0;
for(i=0;i<n;i++)
scanf("%d",&light[i]);
if(n==1)
{
if(light[0]==1)
printf("YES\n");
else
printf("NO\n");
continue;
}
for(i=0;i<n;i++)
{
if(!light[i]) s++;
}
if(s&1) printf("NO\n");
else printf("YES\n");
}
return 0;
}