Codeforces Round #484 (Div. 2) A. Row
生活随笔
收集整理的這篇文章主要介紹了
Codeforces Round #484 (Div. 2) A. Row
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
Example 1
input
3
101
output
YesExample 2
input
4
1011
output
NoExample 3
input
5
10001
output
No
題目大意:
題意:“最大”人數(shù)的作為定義滿足下面兩條:1.相鄰座位沒有人 2.在不違背第一條的情況下,不能在加入一個人分析:
我是先掃一遍座位,有相鄰的1直接輸出No,如果沒有,掃第二遍,是否有3個連續(xù)的0,如果有輸出No,沒有 輸出Yes,值得注意的是開頭跟結(jié)尾為0的情況只要有連續(xù)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 debugfreopen("in.txt", "r", stdin); // freopen("out.txt","w",stdout); #endifcin.tie(0);cout.tie(0);solve();/*#ifdef debugfclose(stdin);fclose(stdout);system("out.txt");#endif*/return 0; }
?
轉(zhuǎn)載于:https://www.cnblogs.com/visualVK/p/9083893.html
總結(jié)
以上是生活随笔為你收集整理的Codeforces Round #484 (Div. 2) A. Row的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: CSS 知识(13---)
- 下一篇: xvfb-run: error: xau