您的位置:首页 > 其它

hdoj N bulbs 5600 (规律)

2015-12-27 22:31 351 查看

N bulbs

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

Total Submission(s): 296    Accepted Submission(s): 168


[align=left]Problem Description[/align]
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.

[align=left]Input[/align]
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

[align=left]Output[/align]
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.

[align=left]Sample Input[/align]

1
5
1 0 0 0 0

[align=left]Sample Output[/align]

YES

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

N bulbs

Accepts: 275 Submissions: 1237 Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) 问题描述
N个灯泡从左到右排成一排,左边的是第一个,右边的最后一个,下标从1到n。有些开着,有些关着,为了节约用电,你要关上所有灯,但是你又很懒。
刚好有个熊孩纸路过,他刚好要从第一个灯泡走去最后一个灯泡,然后离开。
熊孩子从第一个灯泡出发,每次可以往左右两个相邻的灯泡走。
但是毕竟熊孩纸,熊孩纸在离开一个灯泡之前,一定会动一下当前这个灯泡的开关,也就是开的变关,关的变开。
想问你可不可能关完所有的灯,同时熊孩纸也可以到达最后一个灯泡,然后离开。
输入描述
第一行T,表示T组数据。
接下来T组数据:
每组数据,第一行N,后面一行一个01序列,表示灯泡的初始开关状态,0表示关,1表示开。
1≤T≤101\leq T \leq 101≤T≤10
1≤N≤10000001\leq N \leq 10000001≤N≤1000000
输出描述
每组数据,如果可以输出"YES",否则输出"NO"。
输入样例
1
5
1 0 0 0 0
输出样例
YES
Hint
孩子的路径是:123234545
刚好除了第一盏灯,其他灯都只经过偶数次。
//通过举例子找出规律
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
int t,n,x;
int i,cnt;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
cnt=0;
for(i=0;i<n;i++)
{
scanf("%d",&x);
if(x==0)
cnt++;
}
if(cnt&1)
printf("NO\n");
else
printf("YES\n");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: