您的位置:首页 > 其它

杭电5600 N bulbs

2016-01-15 13:29 288 查看


N bulbs

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 460    Accepted Submission(s): 251


Problem Description

N bulbs are in a row from left to right,some are on, and some are off.The first bulb is the most left one. And the last one is the most right one.they are numbered from 1 to n,from left to right.

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.

 

Input

The first line of the input file contains an integer T, which indicates the number of test cases.

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

 

Output

There should be exactly T lines in the output file.

The i-th line should only contain "YES" or "NO" to answer if it's possible to finish.

 

Sample Input

1
5
1 0 0 0 0

 

Sample Output

YES

HintChild's path is: 123234545
all switchs are touched twice except the first one.

 

Source

BestCoder Round #67 (div.2)

 

直接拿样例说,有5个灯泡,第一个开着,其他全关着,问能否从第一个开始,把=走到最后一个,同时使所有的灯泡都处于关着的状态,每走过一个灯泡,灯泡状态都要改变,因为是从头走到尾,也就是每个灯泡都走了一遍,肯定能把原先开着的变成关着的,那么原先关着的就变成开着了,所以就需要把原来关着的走两遍,如果原先关着的灯有奇数个,那么就不能走两遍就不能达到目的,最后遍成了判断原先关着的灯有奇数个还是偶数个,偶数个就是YES,否则就是NO:

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int i,j,k,l,m,n,num;
int main()
{
scanf("%d",&k);
while(k--)
{
scanf("%d",&n);
num=0;
for(i=0;i<n;i++)
{
scanf("%d",&m);
if(m==1)
num++;
}
if(n%2)
{
if(num%2)
printf("YES\n");
else
printf("NO\n");
}
else
{
if(num%2==0)
printf("YES\n");
else
printf("NO\n");
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  技巧 杭电