982A 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.


题意:输入n个椅子数,然后输入一串01字符串,0表示座位为空,1表示座位被占。让你判断给的座位是不是占用最大的。
座位最大满足下面两个条件:

  1. There are no neighbors adjacent to anyone seated.没有座位两个相邻的座位被占。
  2.It's impossible to seat one more person without violating the first rule 如果不违反第一条规则,尽量更多座位被占用。
题解:暴力  最开始,我以为是让座位利用最大,0和1隔开一个才是,结果并不是,输出NO的情况是有三个连续的“000”座位利用率不够,还有就是'11'这种不合法的占座。其余都YES,为了特殊处理一个座位的那种情况,我们可以特判或者首尾都加个'0'.
#include
using namespace std;
int main()
{
    int n;
    string s;
    cin>>n>>s;
    s='0'+s+'0';
    if(s.find("000")==-1&&s.find("11")==-1)  puts("Yes");
    else puts("No");
    return 0;
}


你可能感兴趣的:(ACM日常水题练习集)