hdoj5600N bulbs
2015-12-27 18:46
176 查看
N bulbsTime Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 287 Accepted Submission(s): 162 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. * 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 HintChild's path is: 123234545 all switchs are touched twice except the first one. Source BestCoder Round #67 (div.2) |
那么现在问题是111和nnn同奇偶的情况下,是不是一定有解?答案是显然的。
因为111和nnn同奇偶,所以000的个数是偶数,我们发现当我们从111走到iii时,假设我们往回走到左边某个点kkk,再走回来iii,那么你会发现有且仅有kkk和iii这两个数被设成没有操作。
也就是说我们可以每次任意选择两个点设成没有操作,然而不需操作的点数是偶数个,所以刚好可以满足。
#include<cstdio> #include<cstdlib> #include<cstring> using namespace std; int main() { int t,i,j,k,n,m,ans; scanf("%d",&t); while(t--){ scanf("%d",&n);ans=0; for(i=0;i<n;++i){ scanf("%d",&k); if(k)ans++; } if(((ans&1)&&(n&1))||((ans%2==0&&n%2==0))){ printf("YES\n"); } else { printf("NO\n"); } } return 0; }
相关文章推荐
- hdoj5601N*M bulbs
- Java Web开发中entityBean的习惯用法
- 数值优化(Numerical Optimization)学习系列-共轭梯度方法(Conjugate Gradient)
- C#使用C/C++编译的动态链接库dll
- Ubuntu Apache 部署 Django
- Android SDK Manager国内下载缓慢的问题
- 数值优化(Numerical Optimization)学习系列-信赖域方法
- java分销资源计划平台框架了解及学习
- xampp 500服务器内部错误,
- 数值优化(Numerical Optimization)学习系列-线搜索方法(LineSearch)
- 数值优化(Numerical Optimization)学习系列-概述
- 2016虚拟现实产业链格局将铺设
- 添加JavaScrip
- HTML5<fieldset>标签
- 函数式编程(functional programming)学习总结
- 福建省赛-- Common Tangents(数学几何)
- 关于for循环中i=0与i=arr.length容易被忽视的bug
- Library not loaded: @rpath/libswiftCore.dylib
- 福建省赛-- Common Tangents(数学几何)
- iOS中正则表达式的使用