第20届纪念款-牛客周赛 Round 20 B.C简单构造

B

答案要么是0  要么是1

所以你全部填0或者要么填1然后算就好了

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e5+10;
int n;



void solve()
{
   //全0 全1?
   string str;cin>>str;
   n = str.size();
   string str1 = str;
   int ans1 = 0;
   int tem = 0;
   for(int i=0;i<n;i++){
	   	if((str[i]=='1'||str[i]=='?')){
	   		tem++;
	   	}else tem = 0;
	   	
	   	ans1 = max(ans1,tem);
   }
   int ans2 = 0,tem1 = 0;
   for(int i=0;i<n;i++){
	   	if((str[i]=='0'||str[i]=='?')){
	   		tem1++;
	   	}else tem1 = 0;
	   	
	   	ans2 = max(ans2,tem1);
   }   
   
   cout<<max(ans1,ans2)<<"\n";
   
   
   
   
	
}

int main()
{
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int _;_ = 1;
	while(_--)solve();
}

C

你先算出每一段的起码的长度就好了

t对相邻 故需要连续的1 t+1个

剩余的1为  k-t-1 且需要这么多0

再多的数字的话你直接填上 0 就好了

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e5+10;

int n,k,t;
void solve()
{

 //t+1个连续的1
 //k-t-1剩余的1 至少k-t-1个0
 //n>上面
 
	cin>>n>>k>>t;
	int s11 = t+1;
	int s1 = k-t-1;
	int s0 = k-t-1;
 
	 
	 if(n<s0+s1+s11||s1<0){
	 	cout<<-1;return;
	 }  
 
	int s00 = n-s0-s1-s11;
	
	while(s11--)cout<<1;
	while(s1--)cout<<"01";
	
	while(s00--)cout<<"0";
 	

}

int main()
{
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int _;_ = 1;
	while(_--)solve();
}

  • 9
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值