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

被折叠的 条评论
为什么被折叠?



