N bulbs

 Accepts: 275
 Submissions: 1237
 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,能够愉快的通过,当是奇数个时0001 -->0010而且人在1的位置,于是又从后面开始数0,直至判断最后一个1后还有多少个0即可

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 1000000;
int a[maxn]; int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n;
scanf("%d",&n);
for(int i= 0; i < n; i++)
{
scanf("%d",&a[i]);
}
int num = 0;
int flag = 1;
for(int i = 0; i < n; i++)
{
if(a[i] != 1)
num++;
if(a[i] == 1)
{
if(num % 2 )
{
num = 1;
}
else
num = 0;
}
if(i == n-1)
{
if(num % 2)
flag = 0;
else
flag = 1;
}
}
if(flag == 0)
printf("NO\n");
else
printf("YES\n");
}
return 0;
}

  

hdu 5600 BestCoder Round #67 (div.2)的更多相关文章

  1. BestCoder Round #67 (div.2) N bulbs(hdu 5600)

    N bulbs Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Su ...

  2. hdu 5637 BestCoder Round #74 (div.2)

    Transform  Accepts: 7  Submissions: 49  Time Limit: 4000/2000 MS (Java/Others)  Memory Limit: 131072 ...

  3. HDU 5596/BestCoder Round #66 (div.2) GTW likes math 签到

    GTW likes math  Memory Limit: 131072/131072 K (Java/Others) 问题描述 某一天,GTW听了数学特级教师金龙鱼的课之后,开始做数学<从自主 ...

  4. BestCoder Round #67 (div.2) N*M bulbs

    问题描述 N*M个灯泡排成一片,也就是排成一个N*M的矩形,有些开着,有些关着,为了节约用电,你要关上所有灯,但是你又很懒. 刚好有个熊孩纸路过,他刚好要从左上角的灯泡走去右下角的灯泡,然后离开. 但 ...

  5. hdu5601 BestCoder Round #67 (div.2)

    N*M bulbs  Accepts: 94  Submissions: 717  Time Limit: 10000/5000 MS (Java/Others)  Memory Limit: 655 ...

  6. hdu 5636 搜索 BestCoder Round #74 (div.2)

    Shortest Path  Accepts: 40  Submissions: 610  Time Limit: 4000/2000 MS (Java/Others)  Memory Limit: ...

  7. BestCoder Round #69 (div.2) Baby Ming and Weight lifting(hdu 5610)

    Baby Ming and Weight lifting Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K ( ...

  8. BestCoder Round #68 (div.2) tree(hdu 5606)

    tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submis ...

  9. BestCoder Round #11 (Div. 2) 前三题题解

    题目链接: huangjing hdu5054 Alice and Bob 思路: 就是(x,y)在两个參考系中的表示演全然一样.那么仅仅可能在这个矩形的中点.. 题目: Alice and Bob ...

随机推荐

  1. bzoj千题计划244:bzoj3730: 震波

    http://www.lydsy.com/JudgeOnline/problem.php?id=3730 点分树内对每个节点动态维护2颗线段树 线段树以距离为下标,城市的价值为权值 对于节点x的两棵线 ...

  2. codevs 1283 等差子序列

    http://codevs.cn/problem/1283/ 题目描述 Description 给一个 1 到 N 的排列{Ai},询问是否存在 1<=p1<p2<p3<p4& ...

  3. 数据故障的恢复-MSSQL ndf文件大小变为0 KB恢复过程

    一.故障描述 成都某客户,存储损坏,数据库崩溃.重组存储,恢复数据库文件,发现有四个ndf文件大小变为0 KB.数据库大小约80TB.数据库中有1223个文件,数据库每10天生成一个NDF文件,每个N ...

  4. Docker_部署jenkins(dockerfile实现)

    docker+jenkins开始合体! 我用的是ubuntu14.04的基础镜像,具体的这里不做赘述. 我在/tmp/目录下建了一个Dockerfile文件: touch Dockerfile vi ...

  5. Python内置函数(50)——issubclass

     英文文档: issubclass(class, classinfo) Return true if class is a subclass (direct, indirect or virtual) ...

  6. Spring Cloud的DataRest(二)

    一.创建工程 1.主程序 2.依赖 3.配置 二.案例开发 1.entity 2.repository 三.案例验证 安装postman4.13,启动应用,执行如下案例验证! 1.create - p ...

  7. Linux知识积累(4) Linux下chkconfig命令详解

    Linux下chkconfig命令详解 chkconfig命令主要用来更新(启动或停止)和查询系统服务的运行级信息.谨记chkconfig不是立即自动禁止或激活一个服务,它只是简单的改变了符号连接. ...

  8. MicrosoftWebInfrastructure 之坑

    从svn下载下来的项目,还原提示缺少MicrosoftWebInfrastructure   包 网上大多数解决方法  PM> Install-Package Microsoft.Web.Inf ...

  9. Linux搭建Apache+Tomcat实现负载均衡

    一.首先需要安装java,详见http://www.cnblogs.com/fun0623/p/4350004.html 二.编译安装Apache,详见http://www.cnblogs.com/f ...

  10. Vue框架axios请求(类似于ajax请求)

    Vue框架axios get请求(类似于ajax请求) 首先介绍下,这个axios请求最明显的地方,通过这个请求进行提交的时候页面不会刷新 <!DOCTYPE html> <html ...