第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();
}

相关推荐

  1. Round 29 (A-E , c++)

    2024-01-28 22:40:04       42 阅读
  2. 26

    2024-01-28 22:40:04       36 阅读
  3. Round 29(A B C D E)

    2024-01-28 22:40:04       34 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-01-28 22:40:04       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-01-28 22:40:04       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-01-28 22:40:04       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-01-28 22:40:04       20 阅读

热门阅读

  1. C语言sizeof和strlen区别

    2024-01-28 22:40:04       45 阅读
  2. uniapp微信小程序-前端设计模式学习(中)

    2024-01-28 22:40:04       31 阅读
  3. 南门的树(数组)★★★ c++版本 10分

    2024-01-28 22:40:04       38 阅读
  4. git常见命令

    2024-01-28 22:40:04       28 阅读
  5. 计算机网络(第六版)复习提纲13

    2024-01-28 22:40:04       28 阅读
  6. 在排序数组中查找元素的第一个和最后一个位置

    2024-01-28 22:40:04       31 阅读