zoukankan      html  css  js  c++  java
  • N bulbs(规律)

    N bulbs

     
     Accepts: 408
     
     Submissions: 1224
     Time Limit: 10000/5000 MS (Java/Others)
     
     Memory Limit: 65536/65536 K (Java/Others)
    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 leq T leq 101T10
    • 1 leq N leq 10000001N1000000
    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.
    题解:找了好久的规律,如果是0是偶数就可以走过去再拐回来关了,如果是1走过去就好了,现在就考虑奇数个0时走过了再拐回来关时会有01的向右传递,所以说只要0的奇数段为偶数就好了;
    代码:
    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<cstring>
    #include<vector>
    #include<map>
    #include<algorithm>
    #include<queue>
    using namespace std;
    const int INF=0x3f3f3f3f;
    #define mem(x,y) memset(x,y,sizeof(x))
    #define PI(x) printf("%d",x)
    #define SI(x) scanf("%d",&x)
    #define T_T while(T--)
    const int MAXN=1000010;
    int a[MAXN];
    int main(){
    	int T,N;
    	SI(T);
    	T_T{
    		SI(N);
    		int temp=0,ans=0;
    		for(int i=0;i<N;i++){
    			SI(a[i]);
    		}
    		for(int i=0;i<N;i++){
    			if(a[i]){
    				if(temp&1)ans++;
    				temp=0;
    			}
    			else temp++;
    		}
    		if(temp&1)ans++;
    		//printf("%d
    ",ans);
    		if(ans%2==0)puts("YES");
    		else puts("NO");
    	}
    	return 0;
    }
    

      

  • 相关阅读:
    需求变更的种类及应对方式
    SQL Server中连接远程表、查询其它服务器的数据、导入或导出到其它Sql Server服务器数据
    在IE9中MSWC.BrowserType组件无法识别Cookie的问题
    优秀软件的几个重要标准
    对待代码的态度反应着对待自己的态度
    应对企业不断变化的系统
    在SQL中插入®特殊字符
    如何让领导认识到测试的重要性,在沟通时要注意的几点
    男人要补肾,强肾健脑对能持久做程序
    你可能不知道的Visual Studio 2010使用技巧(VS2010的秘密)
  • 原文地址:https://www.cnblogs.com/handsomecui/p/5079027.html
Copyright © 2011-2022 走看看