Codeforces Round #484 (Div. 2) A. Row

Example 1
input
3
101
output
Yes

Example 2
input
4
1011
output
No

Example 3
input
5
10001
output
No

  

题目大意:

题意:“最大”人数的作为定义满足下面两条:1.相邻座位没有人 2.在不违背第一条的情况下,不能在加入一个人

分析:

    我是先扫一遍座位,有相邻的1直接输出No,如果没有,扫第二遍,是否有3个连续的0,如果有输出No,没有
输出Yes,值得注意的是开头跟结尾为0的情况只要有连续2个0就直接输出No,还有就是只有一个座位的时候在特
判一下

code:

#define debug
#include<bits/stdc++.h>
#define pb push_back
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
#define lson l,m,rt<<1
#define cmm(x) cout<<"("<<(x)<<")";
#define rson m+1,r,rt<<1|1
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll>PLL;
typedef pair<int,ll>Pil;
const ll INF = 0x3f3f3f3f;
const ll inf=0x7fffffff;
const double eps=1e-8;
const int maxn =1e6+10;
const int N = 510;
const ll mod=1e9+7;
const ll MOD=1e9;
//------
//define
int a[maxn]; 
//solve
void solve() {
	int n;
	while(cin>>n){
		string s;
		cin>>s;
		int len=s.size();
		if(len==1){
			if(s[0]=='1'){
				cout<<"Yes"<<endl;
			}else{
				cout<<"No"<<endl;
			}
		}else{
			int flag=0;
			for(int i=0;i<n-1;i++){
				if(s[i]==s[i+1]&&s[i]=='1'){
					flag=1;
					break;
				}
			}
			if(flag){
				cout<<"No"<<endl;
				continue;
			}
			for(int i=0;i<n;i++){
				if(i==0&&s[i]==s[i+1]&&s[i]=='0'){
					flag=1;
					break;
				}
				if(i==n-1&&s[i]==s[i-1]&&s[i]=='0'){
					flag=1;
					break;
				}
				if(s[i]==s[i-1]&&s[i]==s[i+1]&&s[i]=='0'){
					flag=1;
					break;
				}
			}
			if(flag){
				cout<<"No"<<endl;
			}else{
				cout<<"Yes"<<endl;
			}
		}
	}
}

int main() {
	ios_base::sync_with_stdio(false);
#ifdef debug
	freopen("in.txt", "r", stdin);
//	freopen("out.txt","w",stdout);
#endif
	cin.tie(0);
	cout.tie(0);
	solve();
	/*
		#ifdef debug
			fclose(stdin);
			fclose(stdout);
			system("out.txt");
		#endif
	*/
	return 0;
}

  

  

原文地址:https://www.cnblogs.com/visualVK/p/9083893.html