CodeForces - 982A Row

给定一个由0和1组成的字符串,代表一行椅子的占用情况,其中0表示空位,1表示已坐人。判断这个座位安排是否为“最大”,即不存在相邻的人且无法再坐下一个人。通过遍历字符串检查条件来实现模拟验证。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

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.


这题题意是给你一串01串  1代表有人 0代表空位  只要满足1.有人的位置两边不能有人 2.满足1的同时不能再坐下任何一个人  就属于满座状态

这题我选择用模拟去写   将字符串从头到尾扫一遍  遇见0判断前后是否有1 只要存在一个就跳过  否则这个位置还能再坐一个人, 遇见1就判断前后是否有1 去判断字符串是否合法 


#include <cstdio>
const int MAXN = 1e3 + 10;
using namespace std;

int main()
{
    int n;
    scanf("%d", &n);
    getchar();
    char tmp[MAXN];
    scanf("%s", tmp);
    int flag = 0;
    for (int i = 0; i < n; i++)
    {
        if (tmp[i] == '0')
        {
            if ((tmp[i - 1] == '1' && i > 0) || (tmp[i + 1] == '1' && i < n - 1))//如果前或后有人就跳过  否则这位置还能再坐下一人 就不是满座状态
                continue;
            else
                flag = 1;
        }
        else
        {
            if ((tmp[i - 1] == '1' && i > 0) || (tmp[i + 1] == '1' && i < n - 1))//如果有人的位置旁边也有人那么也不符合题意
                flag = 1;
        }
    }
    if (!flag)
        printf("Yes");
    else
        printf("No");
    return 0;
}

 

### 关于Codeforces平台编号为1004的比赛或题目详情 对于编号为1004的具体比赛或题目,在给定的信息中并没有直接提及该编号的相关细节。然而,通常情况下,Codeforces上的每场比赛或问题都有详细的描述页面,其中包括题目列表、提交记录以及讨论区等内容。 为了获取关于编号为1004的确切信息,建议访问Codeforces官方网站并搜索对应编号的比赛或题目[^1]。通过这种方式可以找到最准确和最新的资料。如果这是一个特定的比赛,则其URL可能类似于`https://codeforces.com/contest/1004`;如果是某个具体的问题,则可能是像`https://codeforces.com/problemset/problem/1004/A`这样的形式[^2]。 另外值得注意的是,Codeforces会定期举办不同类型的竞赛活动,包括常规赛、教育赛以及其他特别赛事。因此,了解具体的上下文有助于更精确地定位所需资源。例如,某些特殊日期举办的愚人节大赛也会有独特的编号体系[^3]。 ```python import requests from bs4 import BeautifulSoup def get_contest_info(contest_id): url = f"https://codeforces.com/contest/{contest_id}" response = requests.get(url) if response.status_code == 200: soup = BeautifulSoup(response.text, 'html.parser') title_tag = soup.find('div', class_='title').find_next_sibling('div') problems_section = soup.find(id='problems-section') print(f"Title: {title_tag.text.strip()}") print("Problems:") for row in problems_section.select('.problemindexholder tr')[1:]: cols = row.select('td') index = cols[0].text.strip() name = cols[1].a['href'].split('/')[-1] points = cols[-1].text.strip() print(f"{index}: {name} ({points})") get_contest_info(1004) ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值