hdu 5600 N bulbs
2015-12-27 12:28
218 查看
N bulbs
[b]Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 241 Accepted Submission(s): 132
[/b]
[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.
[align=left]Source[/align]
BestCoder Round #67 (div.2)
好吧,依次把所有的数变成0,到最后一个如果是1就可以关闭所有的灯,否则就不可以
#include <iostream> #include <cstdio> using namespace std; int a[1000000],n; int dfs() { for(int i = 0;i<n-1;i++) { if(!a[i]) { a[i+1] = 1-a[i+1]; } } return a[n-1]; } int main() { int T; scanf("%d",&T); while(T--) { scanf("%d",&n); for(int i = 0;i<n;i++) scanf("%d",&a[i]); if(dfs()) printf("YES\n"); else printf("NO\n"); } return 0; }
相关文章推荐
- hdu5601 N*M bulbs
- Swift中String和UTF8编码的NSData相互转化
- iOS开发,入门级ReactiveCocoa教程(二)
- nodejs+chromium 创建桌面应用程序
- make命令详解
- Android5.0L下因sensorservice crash导致systemserver重新启动的第二种场景分析
- IOS 与ANDROID框架及应用开发模式对照一
- js作用域、异步——学习笔记
- 如何用VC++6.0编写一个游戏
- windows下使用log4j将日志输出到文件,包括system.out
- 浅谈Netfilter框架原理(一)
- GCC结构体内变量对齐
- Open Live Writer (原Windows Live Writer开源)
- AngularJS使用ngMessages进行表单验证
- 中国科学院信息project研究所 第四研究室实习生/应届生招聘
- C# 中如何将一个类文件(XX.CS)封装成.dll文件
- linux(非root) 开机启动tomcat和80端口无法开启解决方案
- 《SDN: Software Defined Networks》笔记--数据中心
- Open Live Writer (原Windows Live Writer开源)
- Android实现短信验证功能(功能的使用)