博客
关于我
HDU 5600 N bulbs (BestCoder Round #67 (div.2))
阅读量:633 次
发布时间:2019-03-14

本文共 1996 字,大约阅读时间需要 6 分钟。

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

Hint

Child’s path is: 123234545
all switchs are touched twice except the first one.

题意:题中给一段0和1组成的序列表示灯的初始状态,有个熊孩子他想从第一个灯泡走到最后一个灯泡,然后离开,在这过程中他可以走到任意一个相邻的灯泡上,可以折返,步数不限,每经过一个灯泡,熊孩子会按下灯泡开关,问你他有没有可能把这段灯泡都关闭。

解题思路: 如果经过1(灯泡开着)则直接走过,如果经过0,则分两种情况,第一种,如果后一个还是 0,则走到下一个,再折返回来,再到下一个时,两个灯泡还是0 0状态,符合题意;第二种,如果后一个是 1 ,则用一个变量记录这种情况出现的次数,通过例子的实验,这种情况如果是偶数次,则通过折返法就能使灯泡都关掉,否则无论怎么走都不可能使全部为 0 。

结论:只要 0 连续出现的偶数段都能用折返法使其为 0 不变,0 连续出现的奇数段的数量为偶数则可以通过0 1的折返转递最终都消为 0 。所以只要计算出 0 连续出现的奇数段的数量判段是不是偶数就可得出答案。

#include
int a[1000005];int main(){ int t,i,j,n; scanf("%d",&t); while(t--) { scanf("%d",&n); for(i=0; i

转载地址:http://bcxoz.baihongyu.com/

你可能感兴趣的文章
Multicast1
查看>>
mysql client library_MySQL数据库之zabbix3.x安装出现“configure: error: Not found mysqlclient library”的解决办法...
查看>>
MySQL Cluster 7.0.36 发布
查看>>
Multimodal Unsupervised Image-to-Image Translation多通道无监督图像翻译
查看>>
MySQL Cluster与MGR集群实战
查看>>
multipart/form-data与application/octet-stream的区别、application/x-www-form-urlencoded
查看>>
mysql cmake 报错,MySQL云服务器应用及cmake报错解决办法
查看>>
Multiple websites on single instance of IIS
查看>>
mysql CONCAT()函数拼接有NULL
查看>>
multiprocessing.Manager 嵌套共享对象不适用于队列
查看>>
multiprocessing.pool.map 和带有两个参数的函数
查看>>
MYSQL CONCAT函数
查看>>
multiprocessing.Pool:map_async 和 imap 有什么区别?
查看>>
MySQL Connector/Net 句柄泄露
查看>>
multiprocessor(中)
查看>>
mysql CPU使用率过高的一次处理经历
查看>>
Multisim中555定时器使用技巧
查看>>
MySQL CRUD 数据表基础操作实战
查看>>
multisim变压器反馈式_穿过隔离栅供电:认识隔离式直流/ 直流偏置电源
查看>>
mysql csv import meets charset
查看>>