zoukankan      html  css  js  c++  java
  • Row

    time limit            per test 
    1 second                memory limit                  per test256 megabytes
    input                  standard input                     output                            standard output

    You're given a row with nn chairs. We call a seating of people "maximal" if the two following conditions hold:

    1. There are no neighbors adjacent to anyone seated.
    2. It's impossible to seat one more person without violating the first rule.

    The seating is given as a string consisting of zeros and ones (00 means that the corresponding seat is empty, 11 — occupied). The goal is to determine whether this seating is "maximal".

    Note that the first and last seats are not adjacent (if n2n≠2).

    Input

    The first line contains a single integer nn (1n10001≤n≤1000) — the number of chairs.

    The next line contains a string of nn characters, each of them is either zero or one, describing the seating.

    Output

    Output "Yes" (without quotation marks) if the seating is "maximal". Otherwise print "No".

    You are allowed to print letters in whatever case you'd like (uppercase or lowercase).

    Examples
    input
    3
    101
    output
    Yes
    input
    4
    1011
    output
    No
    input
    5
    10001
    output
    No
    Note

    In sample case one the given seating is maximal.

    In sample case two the person at chair three has a neighbour to the right.

    In sample case three it is possible to seat yet another person into chair three.

    大意:0代表该座位没有人占,1代表该座位有人占。

        有两个规则: 1,两个1之间必须隔一个0。

              2,使1尽可能多。


    特判一下前两个元素和后两个元素(wa了两发,没考虑后两个元素),中间的元素只需考虑 两个1之间只能隔1~2个0就行了。

    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<iostream>
    #include<string>
    #include<vector>
    #include<stack>
    #include<bitset>
    #include<cstdlib>
    #include<cmath>
    #include<set>
    #include<list>
    #include<deque>
    #include<map>
    #include<queue>
    using namespace std;
    typedef long long ll;
    const double PI = acos(-1.0);
    const double eps = 1e-6;
    const int INF = 1000000000;
    const int maxn = 100;
    int T,n,m;
    
    using namespace std;
    int main()
    {
        int i,n,d1=INF,flag=0;
        char s[1010]={0};
        char emp;
        scanf("%d%c",&n,&emp);
        gets(s);
        for(i=0;i<n;i++)
        {
            if(s[i]=='1')
            {
                d1=i;
                break;
            }
        }
        if(d1>1)
            flag=1;
        for(i=d1+1;i<n;i++)
        {
            if(s[i]=='1')
            {
                if( !((i-d1)==2||(i-d1)==3) ){
                    flag=1;
                    break;
                }
                else
                    d1=i;
            }
        }
        if(n>=2)
        {
            if(s[n-1]=='0'&&s[n-2]=='0')
                flag=1;
        }
        if(flag)
            printf("No
    ");
        else
            printf("Yes
    ");
        return 0;
    }
  • 相关阅读:
    git 常用操作命令行
    Mysql 命令行...
    bootstrap
    10.11 android输入系统_补充知识_activity_window_decor_view关系
    10.10 android输入系统_APP获得并处理输入事件流程
    10.9 android输入系统_APP跟输入系统建立联系和Dispatcher线程_分发dispatch
    10.8 android输入系统_实战_使用GlobalKey一键启动程序
    10.7 android输入系统_Dispatcher线程情景分析_Reader线程传递事件和dispatch前处理
    10.6 android输入系统_Dispatcher线程_总体框架
    10.5 android输入系统_Reader线程_使用EventHub读取事件和核心类及配置文件_实验_分析
  • 原文地址:https://www.cnblogs.com/coder-tcm/p/9057268.html
Copyright © 2011-2022 走看看