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 ...
随机推荐
- Codechef March Challenge 2014——The Street
The Street Problem Code: STREETTA https://www.codechef.com/problems/STREETTA Submit Tweet All submis ...
- raid5 / raid5e / raid5ee的性能对比及其数据恢复原理
RAID 5 是一种存储性能.数据安全和存储成本兼顾的存储解决方案. RAID 5可以理解为是RAID 0和RAID 1的折中方案.RAID 5可以为系统提供数据安全保障,但保障程度要比Mirror低 ...
- STM32F4系列单片机上使用CUBE配置MBEDTLS实现pem格式公钥导入
|版权声明:本文为博主原创文章,未经博主允许不得转载. 最近尝试在STM32F4下用MBEDTLS实现了公钥导入(我使用的是ECC加密),整个过程使用起来比较简单. 首先,STM32F4系列CUBE里 ...
- AJAX使用说明书
AJAX简介 什么是AJAX AJAX(Asynchronous Javascript And XML)翻译成中文就是“异步Javascript和XML”.即使用Javascript语言与服务器进行异 ...
- Python内置函数(34)——filter
英文文档: filter(function, iterable) Construct an iterator from those elements of iterable for which fun ...
- zuul入门(2)zuul的过滤器分类和加载
一.Groovy编写的Filter 1.可以放到指定目录加载 创建一个pre类型的filter,在run方法中获取HttpServletRequest 然后答应header信息 在代码中加入groov ...
- python入门(2)python的安装
python入门(2)python的安装 Python是跨平台的,可以运行在Windows.Mac和各种Linux/Unix系统上. 2.x还是3.x Python有两个版本,一个是2.x版,一个是3 ...
- oracle drop table(表)数据恢复方法
今天不小心把系统用户表给drop掉了,正在运行的系统正式库啊,还好可以恢复 一.查看数据库回收站,看删除的表是否还在回收站select object_name,original_name,partit ...
- python3下搜狗AI API实现
1.背景 a.搜狗也发布了自己的人工智能 api,包括身份证ocr.名片ocr.文本翻译等API,初试感觉准确率一般般. b.基于python3. c.也有自己的签名生成这块,有了鹅厂的底子,相对写起 ...
- Android WebView那些坑之上传文件
最近公司项目需要在WebView上调用手机系统相册来上传图片,开发过程中发现在很多机器上无法正常唤起系统相册来选择图片. 解决问题之前我们先来说说WebView上传文件的逻辑:当我们在Web页面上点击 ...