N bulbs

 Accepts: 408
 Submissions: 1224
 Time Limit: 10000/5000 MS (Java/Others)
 Memory Limit: 65536/65536 K (Java/Others)
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 \leq T \leq 101≤T≤10
  • 1 \leq N \leq 10000001≤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走过去就好了,现在就考虑奇数个0时走过了再拐回来关时会有01的向右传递,所以说只要0的奇数段为偶数就好了;
代码:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<vector>
#include<map>
#include<algorithm>
#include<queue>
using namespace std;
const int INF=0x3f3f3f3f;
#define mem(x,y) memset(x,y,sizeof(x))
#define PI(x) printf("%d",x)
#define SI(x) scanf("%d",&x)
#define T_T while(T--)
const int MAXN=1000010;
int a[MAXN];
int main(){
int T,N;
SI(T);
T_T{
SI(N);
int temp=0,ans=0;
for(int i=0;i<N;i++){
SI(a[i]);
}
for(int i=0;i<N;i++){
if(a[i]){
if(temp&1)ans++;
temp=0;
}
else temp++;
}
if(temp&1)ans++;
//printf("%d\n",ans);
if(ans%2==0)puts("YES");
else puts("NO");
}
return 0;
}

  

N bulbs(规律)的更多相关文章

  1. HDU 5601 N*M bulbs 找规律

    N*M bulbs 题目连接: http://codeforces.com/contest/510/problem/C Description NM个灯泡排成一片,也就是排成一个NM的矩形,有些开着, ...

  2. hdu1452 Happy 2004(规律+因子和+积性函数)

    Happy 2004 题意:s为2004^x的因子和,求s%29.     (题于文末) 知识点: 素因子分解:n = p1 ^ e1 * p2 ^ e2 *..........*pn ^ en 因子 ...

  3. Codeforces Round #384 (Div. 2) B. Chloe and the sequence(规律题)

    传送门 Description Chloe, the same as Vladik, is a competitive programmer. She didn't have any problems ...

  4. ACM/ICPC 之 DP解有规律的最短路问题(POJ3377)

    //POJ3377 //DP解法-解有规律的最短路问题 //Time:1157Ms Memory:12440K #include<iostream> #include<cstring ...

  5. HDU 5795 A Simple Nim 打表求SG函数的规律

    A Simple Nim Problem Description   Two players take turns picking candies from n heaps,the player wh ...

  6. 在sqlserver中做fibonacci(斐波那契)规律运算

    --利用sqlserver来运算斐波那契规律 --利用事物与存储过程 declare @number intdeclare @A intdeclare @B intdeclare @C int set ...

  7. 谈谈黑客攻防技术的成长规律(aullik5)

    黑莓末路 昨晚听FM里谈到了RIM这家公司,有分析师认为它需要很悲催的裁员90%,才能保证活下去.这是一个意料之中,但又有点兔死狐悲的消息.可能在不久的将来,RIM这家公司就会走到尽头,或被收购,或申 ...

  8. Math.abs(~2018),掌握规律即可!

    Math.abs(~2018) 某前端群的入门问题长姿势了,一个简单的入门问题却引发了我的思考,深深的体会到自己在学习前端技术的同时忽略遗忘了一些计算机的基础知识. 对于 JS Math对象没什么可说 ...

  9. COM中需要调用AddRef和Release的10条规律

    COM中需要调用AddRef和Release的10条规律  

随机推荐

  1. BZOJ 2301: [HAOI2011]Problem b( 数论 )

    和POI某道题是一样的...  http://www.cnblogs.com/JSZX11556/p/4686674.html 只需要二维差分一下就行了. 时间复杂度O(MAXN + N^1.5) - ...

  2. org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'springSessionRepositoryFilter' is defined

    spring-session 集成redis,web.xml配置filter时候出现  No bean named 'springSessionRepositoryFilter' is defined ...

  3. [转载]Heritrix 提高效率的若干方法

    摘自http://blog.sina.com.cn/s/blog_6cc084c90100nf39.html --------------------------------------------- ...

  4. Acegi

    https://blogs.oracle.com/darcy/entry/properties_via_annotation_processing http://www.oschina.net/que ...

  5. Android SDK与API版本的对应关系

    看教程.开发Android程序等很多地方,需要设置Android SDK的版本,而其要我们写的却是API版本的数字, 为了方便查看 Android SDK与API版本的对应关系 我在SDK Manag ...

  6. 《火球——UML大战需求分析》(0.1)——开篇废话

    说明: <火球——UML大战需求分析>是我撰写的一本关于需求分析及UML方面的书,我将会在CSDN上为大家分享前面几章的内容,总字数在几万以上,图片有数十张.欢迎你按文章的序号顺序阅读,谢 ...

  7. S3C6410嵌入式应用平台构建(一)

    [2014-4/8~4/10]目前我们已经积累一定的嵌入式相关知识,对嵌入式的架构及开发过程有了大体了解,唯一缺的就是实践,通过自己的分析搭建自己的嵌入式系统.下面,我将从此处开始记录我和我同学一起分 ...

  8. <td style="word-break:break-all"> 在html中控制自动换行

    在html中控制自动换行   其实只要在表格控制中添加一句 <td style="word-break:break-all">就搞定了. 其中可能对英文换行可能会分开一 ...

  9. linux杂谈(十七):iscsi存储分离技术

    1.iscsi简单介绍 ​ ​iSCSI利用了TCP/IP的port 860 和 3260 作为沟通的渠道.透过两部计算机之间利用iSCSI的协议来交换SCSI命令,让计算机能够透过快速的局域网集线来 ...

  10. 【hadoop】14、hadoop2.5的mapreduce的 配置

    配置mapreduce <?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href ...