传送门

虽然是D,但是还是Sb题,把模式串跑一遍KMP,然后把按顺序放,每次放完之后跳到对应的前缀,继续放。

如果最后1的数量还有剩,再将最后的位数全部放1

代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
void read(int &x) {
char ch; bool ok;
for(ok=0,ch=getchar(); !isdigit(ch); ch=getchar()) if(ch=='-') ok=1;
for(x=0; isdigit(ch); x=x*10+ch-'0',ch=getchar()); if(ok) x=-x;
}
#define rg register
const int maxn=5e5+10;
char p[maxn],s[maxn];
int num,num1,len,len1,nxt[maxn],ans;
int main()
{
scanf("%s",p+1),scanf("%s",s+1);
len=strlen(p+1),len1=strlen(s+1);
for(rg int i=1;i<=len;i++)if(p[i]=='1')num++;
for(rg int i=1;i<=len1;i++)if(s[i]=='1')num1++;
if(num<num1||len<len1)
{
for(rg int i=1;i<=len;i++)printf("%c",p[i]);
printf("\n");return 0;
}
for(rg int i=2,j=0;i<=len1;i++)
{
while(j&&s[j+1]!=s[i])j=nxt[j];
if(s[j+1]==s[i])j++;
nxt[i]=j;
}
ans=len+1;
for(rg int i=1,j=0;i<=len;i++)
{
if(num&&s[j+1]=='1')num--,p[i]='1',j++;
else if(s[j+1]=='0')j++,p[i]='0';
else {ans=i;break;}
if(j==len1)j=nxt[j];
}
for(rg int i=ans;i<=len;i++)p[i]='0';
while(num)
{
ans--;
if(p[ans]=='1')num++;
num--,p[ans]='1';
}
for(rg int i=1;i<=len;i++)printf("%c",p[i]);
}

CF1138D.Camp Schedule的更多相关文章

  1. Codeforces Round #545 (Div. 2)-Camp Schedule

    题目要求,给定一个s序列,一个p序列,问能不能对s做相应的调整,使得s序列中,有尽可能多的p子串(可以重复) 最开始我拿到这个题目,也是一点头绪都没有,如何做调整呢? 首先考虑如何会有尽可能多的子串, ...

  2. Codeforces Round #545 (Div. 2)(D. Camp Schedule)

    题目链接:http://codeforces.com/contest/1138/problem/D 题目大意:给你两个字符串s1和s2(只包含0和1),对于s1中,你可以调换任意两个字符的位置.问你最 ...

  3. 【Codeforces 1137B】Camp Schedule

    Codeforces 1137 B 题意:给两个串\(S\).\(T\),问将\(S\)中字符任意调换后出现\(T\)次数最多的方案. 思路:我们首先考虑怎么样放\(T\)才是最优的.我们直观上考虑前 ...

  4. CodeForces Round #545 Div.2

    A. Sushi for Two 代码: #include <bits/stdc++.h> using namespace std; ; ; int a[maxn], vis[maxn]; ...

  5. Codeforces Round #545 (Div. 1) Solution

    人生第一场Div. 1 结果因为想D想太久不晓得Floyd判环法.C不会拆点.E想了个奇奇怪怪的set+堆+一堆乱七八糟的标记的贼难写的做法滚粗了qwq靠手速上分qwqqq A. Skyscraper ...

  6. Codeforces Round #545 Div1 题解

    Codeforces Round #545 Div1 题解 来写题解啦QwQ 本来想上红的,结果没做出D.... A. Skyscrapers CF1137A 题意 给定一个\(n*m\)的网格,每个 ...

  7. Codeforces Round #545 (Div. 1)

    本来开头两道题写得挺快的,然后第三题想了一会儿胡出一个scc计算gcd的做法,写了一发凭借信仰交了上去结果一发pp了?然后第四题沙雕了想了很久才会,于是罚时瞬间变多.结果后面两题都没时间看了,赛后感觉 ...

  8. CodeForces Contest #1137: Round #545 (Div. 1)

    比赛传送门:CF #1137. 比赛记录:点我. 每次都自闭的 div1 啊,什么时候才能上 IM 呢. [A]Skyscrapers 题意简述: 有一个 \(n\times m\) 的矩阵 \(a_ ...

  9. Codeforces Round #545 (Div. 2) 题解

    题目链接 A. Sushi for Two 题意 在一个 01 序列中找出长为偶数的连续的一段使得它前一半和后一半内部分别相同,而前一半和后一半不同. \(2\le n\le 100\ 000\) 题 ...

随机推荐

  1. Kotlin基本语法笔记3之定义类、继承及创建实例

    定义类 class MyObject private constructor(name: String, age: Int) { private var name: String private va ...

  2. 阿里Java开发手册学习 2 异常日志

    异常日志 异常处理 1.不要捕获继承自RuntimeException的运行时异常类,这类异常通常由程序员来校验,来保证查询的健壮性. 2. 不要对大段代码 try catch,分清稳定代码和非稳定代 ...

  3. Multi-lingual Support

    Multi-lingual Support One problem with dealing with non-Latin characters programmatically is that, f ...

  4. HTML5与php实现消息推送功能

    1.html页面basic_sse.html <!DOCTYPE html> <html lang="en"> <head> <meta ...

  5. 常用的ES6

    1 let 和 const 作用域: 只在声明指令的块级作用域内有效.① let所声明的变量可以改变,值和类型都可以改变,没有限制. let a = 123 a = 456 // 正确,可以改变 le ...

  6. [NOIP2011提高组day1]-3-mayan游戏

    3.Mayan 游戏 (mayan.cpp/c/pas) [问题描述] Mayan puzzle 是最近流行起来的一个游戏.游戏界面是一个 7行 5 列的棋盘,上面堆放着一些方块,方块不能悬空堆放,即 ...

  7. Codeforces Round #376 (Div. 2) A. Night at the Museum —— 循环轴

    题目链接: http://codeforces.com/contest/731/problem/A A. Night at the Museum time limit per test 1 secon ...

  8. 使用eclipse的SVN连接码云

    码云配置: 码云的项目上,启用SVN访问 eclipse的配置,不配置这个会报错

  9. PHP 导出office打开乱码

    Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name); ...

  10. SQL Server中数据类型对应C#中数据类型

    在SQL Server 2008中新建数据表的时候有33种数据类型可选,下面分别列举了这些类型对应的C#数据类型 //----------------------------------------- ...