博客
关于我
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/

你可能感兴趣的文章
mysql 导入导出大文件
查看>>
MySQL 导出数据
查看>>
mysql 将null转代为0
查看>>
mysql 常用
查看>>
MySQL 常用列类型
查看>>
mysql 常用命令
查看>>
Mysql 常见ALTER TABLE操作
查看>>
MySQL 常见的 9 种优化方法
查看>>
MySQL 常见的开放性问题
查看>>
Mysql 常见错误
查看>>
mysql 常见问题
查看>>
MYSQL 幻读(Phantom Problem)不可重复读
查看>>
mysql 往字段后面加字符串
查看>>
mysql 快照读 幻读_innodb当前读 与 快照读 and rr级别是否真正避免了幻读
查看>>
MySQL 快速创建千万级测试数据
查看>>
mysql 快速自增假数据, 新增假数据,mysql自增假数据
查看>>
MySql 手动执行主从备份
查看>>
Mysql 批量修改四种方式效率对比(一)
查看>>
Mysql 报错 Field 'id' doesn't have a default value
查看>>
MySQL 报错:Duplicate entry 'xxx' for key 'UNIQ_XXXX'
查看>>