Codeforces Round 958 (Div. 2) B. Make Majority 题型:思维题

43 阅读1分钟

Editorial of Codeforces Round 958 (Div. 2) - Codeforces

思想

因为C0>=C1,就会把[l,r]变为0,因此"11"的个数至少要大于1才行.如果"11"的个数只出现了一次,那么消完之后只有一个1,剩下的全是0,无论如何也不能把支付宝变为"1".

如果只是出现了"111",那么无论如何,该串也可以变为"1"的形式.

第三,首位如果都是"1"的形式,那么一定可以变为"1"的形式

#include<bits/stdc++.h>
using namespace std;

int main()
{
    int t;cin>>t;
	while(t--)
	{
	 int n;cin>>n;
	 int flag=0;
	 int count_11=0;
	 int count_111=0;
	 string s;cin>>s;

	  int pos=s.find("111");
	  while(pos!=string::npos) 
	  {
	  	count_111++;
	  	pos=s.find("111",pos+1); //从pos+1开始继续找下一个"111" 
	  }
	  pos=s.find("11");
	  while(pos!=string::npos) 
	  {
	  	count_11++; 
		pos=s.find("11",pos+1);	
	  }
	 	
	 if(count_11>=2) flag=1;
	 if(count_111>=1)flag=1;
	 if(s[0]=='1' && s[n-1]=='1')flag=1;
	 if(count_11>=1 &&(s[0]=='1'||s[n-1]=='1')) flag=1;
     if(flag)cout<<"yes"<<endl;
     else cout<<"no"<<endl;
	}	
	return 0;
} 

image.png