zoukankan      html  css  js  c++  java
  • hdu 5600 BestCoder Round #67 (div.2)

    N bulbs

     
     Accepts: 275
     
     Submissions: 1237
     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,能够愉快的通过,当是奇数个时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
    ");
            else
                printf("YES
    ");
        }
        return 0;
    }
    

      

  • 相关阅读:
    C# GridView使用 与 DataList分页。
    如何禁止服务器端口 135 137 3389等
    页面自动刷新 与 隔时刷新
    彻底解决网页图片只能另存为无标题bmp位图
    C# Byte[]数组转化为string类型.其实很简单.
    vs2003打开时报错。尝试创建 Web 项目或打开位于..
    Discuz! 在线人数,发帖数,修改。
    点击文本框出现时间选择器DateJs
    一张有转折意义的神秘地图
    中断异常的处理
  • 原文地址:https://www.cnblogs.com/Przz/p/5409658.html
Copyright © 2011-2022 走看看