hdu 5600 N bulbs(BC——思维题)

来源:互联网 发布:淘宝企业店铺开直通车 编辑:程序博客网 时间:2024/06/08 06:00

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5600

N bulbs

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 778    Accepted Submission(s): 395


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.

1T10
1N1000000
 

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
151 0 0 0 0
 

Sample Output
YES
Hint
Child's path is: 123234545all switchs are touched twice except the first one.
 

Source
BestCoder Round #67 (div.2)
 
题目大意:
N个灯泡从左到右排成一排,左边的是第一个,右边的最后一个,下标从1到n。有些开着,有些关着,为了节约用电,你要关上所有灯,但是你又很懒。刚好有个熊孩纸路过,他刚好要从第一个灯泡走去最后一个灯泡,然后离开。熊孩子从第一个灯泡出发,每次可以往左右两个相邻的灯泡走。但是毕竟熊孩纸,熊孩纸在离开一个灯泡之前,一定会动一下当前这个灯泡的开关,也就是开的变关,关的变开。想问你可不可能关完所有的灯,同时熊孩纸也可以到达最后一个灯泡,然后离开。
规律:0个个数是偶数就可以。
详见代码。
#include <iostream>#include <cstdio>using namespace std;int main(){    int T;    scanf("%d",&T);    while (T--)    {        int n,x;        scanf("%d",&n);        int num=0;        for (int i=1;i<=n;i++)        {            scanf("%d",&x);            if (x==0)                num++;        }        if (num%2==0)            printf ("YES\n");        else            printf ("NO\n");    }    return 0;}


0 0
原创粉丝点击