zoukankan      html  css  js  c++  java
  • 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 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.

    1T10
    1N1000000
     
    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
    ");
    			else
    			    printf("NO
    ");
    			continue;
    		}
    		for(i=0;i<n;i++)
    		{
    			if(!light[i]) s++;
    		}
    		if(s&1) printf("NO
    ");
    		else printf("YES
    ");
    	}   
    	return 0;
    } 
    

      

  • 相关阅读:
    【数据库】python访问mysql
    给vs2015添加EF
    SQL Sever 2008 R2版本添加Northwin数据库错误解决
    c#进程、定时器初步学习
    联动下拉框显示省市县
    第一次网站初尝试爬的坑
    关闭程序主窗体程序不结束,主要应用于登录界面
    基于三层架构的增删改查Get知识点
    python中的异常捕获怎么用?
    VS版本下载
  • 原文地址:https://www.cnblogs.com/tonghao/p/5171171.html
Copyright © 2011-2022 走看看