A. Row

本文介绍了一个关于座位安排的问题,需要判断给定的座位排列是否为最大就坐安排,即是否满足无人相邻且无法通过增加人员而不违反无人相邻规则的情况。文章提供了具体的输入输出示例及解决该问题的C语言代码。

A. Row
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
You’re given a row with
n
chairs. We call a seating of people “maximal” if the two following conditions hold:

There are no neighbors adjacent to anyone seated.
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 (
0
means that the corresponding seat is empty,
1
— occupied). The goal is to determine whether this seating is “maximal”.

Note that the first and last seats are not adjacent (if
n

2
).

Input
The first line contains a single integer
n
(
1

n

1000
) — the number of chairs.

The next line contains a string of
n
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
inputCopy
3
101
outputCopy
Yes
inputCopy
4
1011
outputCopy
No
inputCopy
5
10001
outputCopy
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.

#include <stdio.h>
#include <stdlib.h>
#include<string.h>
char a[1010];
int main()
{
    int n,i;
    int flag=0;
    scanf("%d%s",&n,a+1);
    a[0]='0';
    a[n+1]='0';
    for(i=1;i<=n;i++)
    {
        if((a[i-1]=='0'&&a[i]=='0'&&a[i+1]=='0')||(a[i]=='1'&&a[i+1]=='1'))
        {
            flag=1;
            break;
        }
    }
    if(flag==1)printf("No\n");
    else printf("Yes\n");
    return 0;
}

题意:题目是说不能有挨着的11或者000,那对于边上的00,100,001,这种情况完全可以把边上的0换成1,这种是不符合条件的,只需要在左右边上加上0,看是不是满足000就可以

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值