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

 

 

posted @ 2018-05-18 17:52  Termin  阅读(337)  评论(0)    收藏  举报
编辑推荐:
· 复杂业务系统线上问题排查过程
· 通过抓包,深入揭秘MCP协议底层通信
· 记一次.NET MAUI项目中绑定Android库实现硬件控制的开发经历
· 糊涂啊!这个需求居然没想到用时间轮来解决
· 浅谈为什么我讨厌分布式事务
阅读排行:
· Coze Studio:字节跳动 Coze 的开源版本来了!第一时间深度解析
· 为大模型 MCP Code Interpreter 而生:C# Runner 开源发布
· 面试时该如何做好自我介绍呢?附带介绍样板示例!!!
· 复杂业务系统线上问题排查过程
· 独立开发:高效集成大模型,看这篇就够了
点击右上角即可分享
微信分享提示