HDOJ 5600-N bulbs【模拟】
来源:互联网 发布:淘宝卖家怎么评差评 编辑:程序博客网 时间:2024/06/06 09:31
N bulbs
N bulbs
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 788 Accepted Submission(s): 401
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.
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
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.
*
*
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.
The i-th line should only contain "YES" or "NO" to answer if it's possible to finish.
Sample Input
151 0 0 0 0
Sample Output
YESHintChild's path is: 123234545all switchs are touched twice except the first one.
Source
BestCoder Round #67 (div.2)
解题思路:
按照每一位每一位的操作,就是从一个位置走到头,拐回来走到这个位置的后一个,我们可以看出1这个位置是直接可以跳过的,而0这个位置要将下一位反转。
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int map[1000020];int main(){int t;scanf("%d",&t);while(t--){int n;scanf("%d",&n);for(int i=1;i<=n;i++){scanf("%d",&map[i]);}for(int i=1;i<=n-1;i++){if(map[i]==0){map[i+1]=1-map[i+1];}}if(map[n]){printf("YES\n");}elseprintf("NO\n");}return 0;}
0 0
- HDOJ 5600-N bulbs【模拟】
- HDOJ 5600 N bulbs
- hdoj N bulbs 5600 (规律)
- hdu 5600 N bulbs
- HDU 5600:N bulbs
- hdu 5600 N bulbs
- HDU 5600 N bulbs
- hdoj N*M bulbs 5601 (规律)
- 杭电5600 N bulbs
- HDU 5600 N bulbs(机智)
- HDU -- 5600 N bulbs 【思维 + 规律】
- hdu5601 N*M bulbs
- HDU5601:N*M bulbs
- HDU5600:N bulbs
- hdu5600 N bulbs
- Bulbs 【模拟】or 【set】
- hdu 5601(5600) /BC 67B(A) N*M bulbs
- hdu 5600 N bulbs(BC——思维题)
- STL乱搞 Codeforces675D Tree Construction
- PPT怎么x的几次方?
- Digilent Basys2开发板驱动安装失败
- 初学JAVA环境变量配置以及编译程序和运行
- LightOj--1071--Baker Vai(拆点最大费用流)
- HDOJ 5600-N bulbs【模拟】
- Java基础 - 1.Java 语言特性及其基本语法
- 算法设计☞快速排序
- CROC 2016 - Elimination Round(A)bfs
- PPT如何存出文稿中的图片
- POJ 2411 Mondriaan'sDream(状压DP)
- 线段_线段树
- JS学习14(Canvas)
- LeetCode:Remove Duplicates from Sorted Array