zoukankan      html  css  js  c++  java
  • Codeforces Round #484 (Div. 2) A. Row

    A. Row
    time limit per test
    1 second
    memory limit per test
    256 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
    Copy
    3
    101
    output
    Copy
    Yes
    input
    Copy
    4
    1011
    output
    Copy
    No
    input
    Copy
    5
    10001
    output
    Copy
    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.

    【题意】:

    题意就是1代表这个位置有坐人,0代表这个位置没有坐人。

    如果1旁边有坐人,就是No

    如果空位置还能放下一个1,也是No

    【思路】:

    我发现如果有3个连续的0的话,肯定是No

    如果有两个连接的1的话,肯定也是No

    所以我一开始写了一个判断3个0的,然后wa

    后来想了一下,两个连续的0也可能导致No

    比如,001 or 100

    然后我发现了一下就是一开始两个0或者是结尾两个0,

    这种情况就没其他的。

    特判一下就可以了;

    但是还是wa。

    然后我想会不会是一个数的时候出现问题

    果然一个0也有可能是No

    针对于0

    这种情况

    然后考虑完后一发ac

    附上代码:

    #include<cstdio>
    #include<iostream>
    #include<cstring>
    using namespace std;
    const int MAXN = 1005;
    char team[MAXN];
    
    int main()
    {
        int n;
        while(~scanf("%d",&n))
        {//printf("...
    ");
            memset(team,0,sizeof(team));
            scanf("%s",team);
            int ans=0;
            int flag=0;
            for(int i=0; i<n; i++)
            {if(n==1&&team[i]-'0'==0)
            {
                flag=1;
                break;
            }
                if(team[i]-'0'==0)
                {ans++;
                if(ans>=3)
                {
                    flag=1;
                    break;
                }
                if(ans==2)
                {
                    if(i==1||i==n-1)
                    {flag=1;
                    break;
                    }
                }
                }
                else
                    if(team[i]-'0'==1)
                {
                    ans=0;
                    if(team[i-1]-'0'==1||team[i+1]-'0'==1)
                    {
                        flag=1;
                        break;
                    }
                }
            }
            if(flag)
                printf("No
    ");
            else
                printf("Yes
    ");
        }
        return 0;
    }
  • 相关阅读:
    Kylin 与 Spark SQL相比,有哪些差异和优势?
    apache kylin2.10在原生hadoop集群上安装
    ambari安装 QA
    mysql 5.7 学习
    Public key for ambari-server-2.4.2.0-136.x86_64.rpm is not installed 安装ambari报错总结
    python 练习
    centos 扩容
    Linux中Cache内存占用过高解决办法
    HyperLogLog
    星型模式、雪花模式和事实星座模式
  • 原文地址:https://www.cnblogs.com/qq136155330/p/9069529.html
Copyright © 2011-2022 走看看