N bulbs

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 559    Accepted Submission(s): 298

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≤T≤10
* 1≤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.

 
题意:有n个灯泡,其中有开着的有关着的,现在让你从第一个灯泡开始把所有灯都关掉,且关掉的最后一盏灯刚好是位于n位置的灯泡,问是否能达到题目的要求
要求:1、可以往返走动  2、关掉的最后一盏灯的位置应该是n位置3、每次离开一盏灯时 灯泡的状态都会发生改变
题解:每次考虑两盏灯,不论前一盏灯的状态如何我们都可以通过与后一盏灯之间来回走动使钱一盏灯变为关闭状态,当前后两盏灯的状态相同时(即都为0 0或者 1 1)我们可以使这两盏灯都关闭,如果前后两盏灯的状态不同(0 1或1 0)那么最后一步后一盏灯的状态为开(1),所以我们依次遍历到最后一盏灯,观察最后一盏灯的状态即可,经过1时我们可以将其变为0,所以我们统计0的个数,如果是偶数,可以实现如果是奇数不可实现
#include<stdio.h>
#include<string.h>
#include<string>
#include<math.h>
#include<algorithm>
#define LL long long
#define PI atan(1.0)*4
#define DD doublea
#define MAX 1001000
#define mod 10007
using namespace std;
int light[MAX];
int main()
{
int n,m,j,i,s,t;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
s=0;
for(i=0;i<n;i++)
scanf("%d",&light[i]);
if(n==1)
{
if(light[0]==1)
printf("YES\n");
else
printf("NO\n");
continue;
}
for(i=0;i<n;i++)
{
if(!light[i]) s++;
}
if(s&1) printf("NO\n");
else printf("YES\n");
}
return 0;
}

  

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

  1. BestCoder Round #70 Jam's math problem(hdu 5615)

    Problem Description Jam has a math problem. He just learned factorization. He is trying to factorize ...

  2. CF Round #600 (Div 2) 解题报告(A~E)

    CF Round #600 (Div 2) 解题报告(A~E) A:Single Push 采用差分的思想,让\(b-a=c\),然后观察\(c\)序列是不是一个满足要求的序列 #include< ...

  3. BestCoder Round #74 (div.1) 1002Shortest Path(hdoj5636)

    哈哈哈哈,我就知道这道题目再扔给我,我还是不会,就是这么菜,哈哈哈 一开始官方题解就没搞懂-然后就看了一下别人的代码,水水过就算了.今天拿到-GG: 题意: 一开始,有一张原图,有一条长度为n的链. ...

  4. Codeforces Round #378 (Div. 2) D题(data structure)解题报告

    题目地址 先简单的总结一下这次CF,前两道题非常的水,可是第一题又是因为自己想的不够周到而被Hack了一次(或许也应该感谢这个hack我的人,使我没有最后在赛后测试中WA).做到C题时看到题目情况非常 ...

  5. Codeforces Round #367 (Div. 2) A. Beru-taxi (水题)

    Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b ...

  6. Codeforces Round #617 (Div. 3) String Coloring(E1.E2)

    (easy version): 题目链接:http://codeforces.com/contest/1296/problem/E1 题目一句话就是说,两种颜色不同的字符可以相互换位, 问,对这字符串 ...

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

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

  8. hdu 5600 BestCoder Round #67 (div.2)

    N bulbs  Accepts: 275  Submissions: 1237  Time Limit: 10000/5000 MS (Java/Others)  Memory Limit: 655 ...

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

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

随机推荐

  1. 将Ftp添加到资源管理器中直接使用

    在资源管理器中,右键,添加网络位置. 然后输入ftp的url ftp://server2008 使用匿名方式登录

  2. window注册表

    打开注册表: 可以用快捷键 win + r  ,然后输入 Regedit 回车,会打开注册表. 注册表添加一个键值对到 操作如下: 1.先创建一个 .reg 后缀的文件. 2.文件内容如下: Wind ...

  3. UVa 1467 (贪心+暴力) Installations

    题意: 一共有n项服务,每项服务有安装的时间s和截止时间d.对于每项任务,如果有一项超出截止时间,惩罚值为所超出时间的长度.问如何安装才能使惩罚值最大的两个任务的惩罚值之和最小. 分析: 如果是求总惩 ...

  4. 由于管理员设置的策略,该磁盘处于脱机状态-Win 2008 R2

    问题截图: 做了个小说网站www.114369.cn,使用的是云主机,系统是Win 2008 R2,进入服务器后发现磁盘有问题 只有c盘,没有d盘,提示:由于管理员设置的策略,该磁盘处于脱机状态 解决 ...

  5. 【django】request

    request.GET request.POST

  6. LeetCode: Word Break I && II

    I title: https://leetcode.com/problems/word-break/ Given a string s and a dictionary of words dict, ...

  7. 最简单的视音频播放示例7:SDL2播放RGB/YUV

    本文记录SDL播放视频的技术.在这里使用的版本是SDL2.实际上SDL本身并不提供视音频播放的功能,它只是封装了视音频播放的底层API.在Windows平台下,SDL封装了Direct3D这类的API ...

  8. 使用ffmpeg实现转码样例(代码实现)

    分类: C/C++ 使用ffmpeg实现转码样例(代码实现) 使用ffmpeg转码主要工作如下: Demux -> Decoding -> Encoding -> Muxing 其中 ...

  9. MySQL基础之第9章 触发器

    触发器(TRIGGER)是由事件来触发某个操作.这些事件包括INSERT语句.UPDATE语句和DELETE语句.当数据库系统执行这些事件时,就会激活触发器执行相应的操作.MySQL从5.0.2版本开 ...

  10. GCC 编译优化指南

    转自: http://www.jinbuguo.com/linux/optimize_guide.html GCC 编译优化指南 作者:金步国[www.jinbuguo.com] 版权声明 本文作者是 ...