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. django获取ip与数据重复性判定

    获取ip if request.META.has_key('HTTP_X_FORWARDED_FOR'): ip_c = request.META['HTTP_X_FORWARDED_FOR'] el ...

  2. 同一个页面同时拥有collectionView和navigationBar和tabBar时可能遇到的问题

    写一个页面的时候,遇到了页面加载时候collectionView的最下面少了49个像素的位置,切换去别的页面之后,再返回,又变回正常,多方求解无果后,发现原来是系统自带的适应功能导致的,加入以下代码即 ...

  3. Linux命令及lamp搭建

    单纯属于Linux的命令:1.强制卸载有依赖关系的软件包: rpm -e httpd-2.2.15-26.el6.x86_64 --nodeps(--nodeps表示无依赖)4.删除当前目录所有的文件 ...

  4. JavaScript 轮播图实例

    HTML代码: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <t ...

  5. Django REST framework+Vue 打造生鲜超市(二)

    三.Models设计 3.1.项目初始化 (1)进虚拟环境下安装 django2.0.2 djangorestframework和相关依赖mark,filter pillow  图片处理 pip in ...

  6. 可空类型 Nullable<T>

    Nullable<T> 内部实现了显示和隐式转换 显示转换: public static explicit operator T(T? value) { return value.Valu ...

  7. Zepto.js库touch模块代码解析

    Zepto.js也许并不陌生,专门针对移动端开发,Zepto有一些基本的触摸事件可以用来做触摸屏交互(tap事件.swipe事件),Zepto是不支持IE浏览器的. 下面来解析一些Zepto.js触摸 ...

  8. 返回到前台的String出现乱码问题

    使用springmvc给前天返回String类型的数据出现乱码问题可以在配置环境Spring-mvc.xml中添加如下代码 <mvc:annotation-driven> <mvc: ...

  9. kafka和mqtt的区别是什么?

    两者都是从传统的Pub/Sub消息系统演化出来的,但是进化方向不一样,比较如下: Kafka是为了数据集成的场景,与以往Pub/Sub消息总线不一样,通过分布式架构提供了海量消息处理.高容错的方式存储 ...

  10. Linux下的Shell编程(2)环境变量和局部变量

    Shell Script是一种弱类型语言,使用变量的时候无需首先声明其类型. 局部变量在本地数据区分配内存进行存储,这个变量归当前的Shell所有,任何子进 程都不能访问本地变量.这些变量与环境变量不 ...