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 n≠2n≠2).

Input

The first line contains a single integer nn (1≤n≤10001≤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

3101

output

Copy

Yes

input

Copy

41011

output

Copy

No

input

Copy

510001

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("...\n");
        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\n");
        else
            printf("Yes\n");
    }
    return 0;
}

原文地址:https://www.cnblogs.com/qq136155330/p/9069529.html

时间: 2024-10-04 04:56:20

Codeforces Round #484 (Div. 2) A. Row的相关文章

Codeforces Round #484 (Div. 2) B. Bus of Characters(markdowm版)

Codeforces Round #484 (Div. 2) B. Bus of Characters B. Bus of Characters time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output In the Bus of Characters there are nn rows of seat, each having 22

Codeforces Codeforces Round #484 (Div. 2) E. Billiard

Codeforces Codeforces Round #484 (Div. 2) E. Billiard 题目连接: http://codeforces.com/contest/982/problem/E Description Consider a billiard table of rectangular size $n \times m$ with four pockets. Let's introduce a coordinate system with the origin at t

Codeforces Codeforces Round #484 (Div. 2) D. Shark

Codeforces Codeforces Round #484 (Div. 2) D. Shark 题目连接: http://codeforces.com/contest/982/problem/D Description For long time scientists study the behavior of sharks. Sharks, as many other species, alternate short movements in a certain location and

【set】【multiset】Codeforces Round #484 (Div. 2) D. Shark

题意:给你一个序列,让你找一个k,倘若把大于等于k的元素都标记为不可用,那么剩下的所有元素形成的段的长度相同,并且使得段的数量尽量大.如果有多解,输出k尽量小的. 把元素从大到小排序插回原位置,用一个set维护前驱后继,相当于删除一个原有的段,然后将这个段切成两半,产生两个新的段.维护这次操作后所有段的长度以及各种长度的出现次数(用multiset),一旦合法,就尝试更新答案. #include<cstdio> #include<algorithm> #include<set

Codeforces Round #484 (Div. 2)

Link A.B 签到 C 分析 赛时wa7起不来 D 题意 分析 原文地址:https://www.cnblogs.com/Deadline/p/9058253.html

Codeforces Round #368 (Div. 2) Brain&#39;s Photos

Brain's Photos Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead. As you may know, the coolest photos

Codeforces Round #262 (Div. 2) 题解

A. Vasya and Socks time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasya has n pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When

Codeforces Round #356 (Div. 2) [Codeforces680]

此处有目录↑ Codeforces Round #356(Div. 2):http://codeforces.com/contest/680 A. Bear and Five Cards (贪心) time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A little bear Limak plays a game. He has

Codeforces Round #262 (Div. 2) 460C. Present(二分)

题目链接:http://codeforces.com/problemset/problem/460/C C. Present time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Little beaver is a beginner programmer, so informatics is his favorite subjec