Codeforces Round #484 (Div. 2) Codeforces982A. 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 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
Copy
3
101
output
Copy
Yes
input
Copy
4
1011
output
Copy
No
input
Copy
5
10001
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.

传送门:http://codeforces.com/problemset/problem/982/A

题意:输入一个n和一个01构成的长度为n的字符串,1代表有人坐着,0代表没人。题目希望1.没有两个人挨着坐2.无法再往这个座位安排里加人(1)了。

思路:①没有两个人挨着坐,就是要没有两个连续的1  ②无法加人,也就是说不会有000的情况,不然可以把中间的变成1,且在首尾的时候,如果有两个连续的0,第一个0必定可以变成1,所以如果第一个字符是0,第二个必须是1,第一个是1,第二个必须是0,也就是说首两个字符一定要不一样,尾部同理。③如果只有一个0的话是可以把它变成1的所以这种情况是no哦

吐槽:一开始把不能安插人想成了不能两个0连续,又疯了一个

代码:

#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<string>
#include<iostream>
#include<map>
#include<vector>
#include<set>
#include<queue>
using namespace std;
const int inf=0x3f3f3f3f;


int main()
{
	int n;
	int flag=0;
	string s;
	cin>>n;
	getchar();
	cin>>s;
	for(int i=0;i<n-2;i++)
	{
		if((s[i]=='1'&&s[i+1]=='1')||(s[i]=='0'&&s[i+1]=='0'&&s[i+2]=='0'))
		{
			flag=1;
		}
	}
	if(s[n-1]==s[n-2]||s[0]==s[1])
		flag=1;
	if(s=="0")
		flag=1;
	if(flag)
		cout<<"No"<<endl;
	else
		cout<<"Yes"<<endl;

	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_39396954/article/details/80956653