You're given a row with nn 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 (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).
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 "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).
3 101
Yes
4 1011
No
5 10001
No
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 <cstdio>
#include <iostream>
#include <string.h>
#include <string>
#include <map>
#include <queue>
#include <deque>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <stack>
#include <iomanip>
#define mem0(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,0x3f,sizeof(a))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
const int maxn=100005,inf=0x3f3f3f3f;
const ll llinf=0x3f3f3f3f3f3f3f3f;
const ld pi=acos(-1.0L);
char s[maxn];
int main() {
int n;
scanf("%d",&n);
scanf("%s",s+1);
int flag=1;
for (int i=1;i<=n;i++) {
if (s[i]=='1'){
if ((s[i-1]=='1'&&i!=1)||(s[i+1]=='1'&&i!=n)) flag=0;
} else {
if ((s[i-1]=='0'||i==1)&&(s[i+1]=='0'||i==n)) flag=0;
}
}
if (flag) cout << "yes"; else cout << "no";
return 0;
}
In the Bus of Characters there are nn rows of seat, each having 22 seats. The width of both seats in the ii-th row is wiwi centimeters. All integers