hdu 5600 BestCoder Round #67 (div.2)
N bulbs
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.
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
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.
1
5
1 0 0 0 0
YES
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)的更多相关文章
- 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 ...
- hdu 5637 BestCoder Round #74 (div.2)
Transform Accepts: 7 Submissions: 49 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072 ...
- HDU 5596/BestCoder Round #66 (div.2) GTW likes math 签到
GTW likes math Memory Limit: 131072/131072 K (Java/Others) 问题描述 某一天,GTW听了数学特级教师金龙鱼的课之后,开始做数学<从自主 ...
- BestCoder Round #67 (div.2) N*M bulbs
问题描述 N*M个灯泡排成一片,也就是排成一个N*M的矩形,有些开着,有些关着,为了节约用电,你要关上所有灯,但是你又很懒. 刚好有个熊孩纸路过,他刚好要从左上角的灯泡走去右下角的灯泡,然后离开. 但 ...
- hdu5601 BestCoder Round #67 (div.2)
N*M bulbs Accepts: 94 Submissions: 717 Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 655 ...
- hdu 5636 搜索 BestCoder Round #74 (div.2)
Shortest Path Accepts: 40 Submissions: 610 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: ...
- 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 ( ...
- 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 ...
- BestCoder Round #11 (Div. 2) 前三题题解
题目链接: huangjing hdu5054 Alice and Bob 思路: 就是(x,y)在两个參考系中的表示演全然一样.那么仅仅可能在这个矩形的中点.. 题目: Alice and Bob ...
随机推荐
- js判断flash文件是否加载完毕
轮询判断加载进度 img的加载完成有onload方法,一直不知道该怎么判断swf文件是否加载完毕了? 在应用中使用了轮询判断加载进度值PercentLoaded是否达到100,经测试,可以达到效果. ...
- ThinkPad安装deepin操作系统报错解决方法
目前deepin操作系统,软件也比较多,所以想在自己的thinkpad t430笔记本上安装.但是安装时报错,具体错误忘了看了.反复试了好几次都不行,最后在网上查了,讲bios设置调整之后可以正常安装 ...
- JAVA_SE基础——45.基本类型变量.值交换[独家深入解析]
需求:定义一个函数交换两个基本类型变量的值. 相信看过我前面的文章的同学都应该看的懂我以下的代码: class Demo2 { public static void main(String[] arg ...
- php面向对象相关内容
1.什么是面向对象? 面向对象编程(Object Oriented Programming, OOP, 面向对象程序设计)是一种计算机编程架构,OOP的一条基本原则是计算机程序是由单个能够起到子程序作 ...
- 分贝块---dBblock
分贝,用英语来表达的话,是decibel,是量度两个相同单位之数量比例的计量单位,主要用于度量声音强度,常用dB表示. 块,block,在百度百科中,指数据库中的最小存储和处理单位,包含块本身的头信息 ...
- SpringMvc返回报文形式的控制-验证方法: JSON or HTML or XML
首先,请求通过accept请求头声明了支持的返回格式 然后,框架根据该请求头和代码实现(注解)选择了对应的MessageConverter处理返回! 一.验证过程 1.返回html 1.1.请求组装 ...
- GIT入门笔记(13)- GUI GIT
- Spring Security入门(3-3)Spring Security 手工配置并注入 authenticationProvider 和 异常信息传递
特别注意的是 这样就能保证抛出UsernameNotFoundException时,前台显示出错信息: 另外,ps:
- C# word文档转换成PDF格式文档
最近用到一个功能word转pdf,有个方法不错,挺方便的,直接调用即可,记录下 方法:ConvertWordToPdf(string sourcePath, string targetPath) so ...
- Python之函数基础
1.函数的定义与调用 函数从大方针上考虑总共分为两种:一种是内置函数,另一种是自定义函数.今天主要讲的是自定义函数. s = '金老板小护士' #len(s) def my_len(): #自定义函数 ...