题目链接:http://codeforces.com/contest/1138/problem/D

题目大意:给你两个字符串s1和s2(只包含0和1),对于s1中,你可以调换任意两个字符的位置。问你最多能在s1中构造出几个s2(可重叠)。

具体思路:首先找到字符串s2的最小循环节,比如说1101,我们找到的最小循环节就是101,这样的话,我们每次在后面加上101就能构造出一个新的1101了,最小循环节是最小的代价。

AC代码:

 #include<bits/stdc++.h>
using namespace std;
const int maxn = 6e5+;
char str1[maxn],str2[maxn];
char str[maxn];
int nex[maxn];
void getnex(int len){
nex[]=-;
int i=,j=-;
while(i<len){
if(j==-||str2[i]==str2[j]){
i++;
j++;
nex[i]=j;
}
else {
j=nex[j];
}
}
}
int main(){
scanf("%s %s",str1,str2);
int len1=strlen(str1);
int len2=strlen(str2);
getnex(len2);
int len=;
int tmp=len2-nex[len2];
for(int i=len2-tmp;i<=len2-;i++){
str[len++]=str2[i];
}
//cout<<str<<endl;
int s0=,s1=;
for(int i=;i<len1;i++){
if(str1[i]=='')s1++;
if(str1[i]=='')s0++;
}
int t0=,t1=;
for(int i=;i<len2;i++){
if(str2[i]=='')t1++;
if(str2[i]=='')t0++;
}
if(s0<t0||s1<t1){
printf("%s\n",str1);
return ;
}
t0=,t1=;
for(int i=;i<len;i++){
if(str[i]=='')t1++;
if(str[i]=='')t0++;
}
for(int i=;i<len2-tmp;i++){
printf("%c",str2[i]);
if(str2[i]=='')s1--;
else s0--;
}
while(s0>=t0&&s1>=t1){
s0-=t0;
s1-=t1;
printf("%s",str);
}
while(s0>)printf(""),s0--;
while(s1>)printf(""),s1--;
printf("\n");
}

Codeforces Round #545 (Div. 2)(D. Camp Schedule)的更多相关文章

  1. Codeforces Round #344 (Div. 2)(按位或运算)

    Blake is a CEO of a large company called "Blake Technologies". He loves his company very m ...

  2. D2. Kirk and a Binary String (hard version) D1 Kirk and a Binary String (easy version) Codeforces Round #581 (Div. 2) (实现,构造)

    D2. Kirk and a Binary String (hard version) time limit per test1 second memory limit per test256 meg ...

  3. Codeforces Round #268 (Div. 2) (被屠记)

    c被fst了................ 然后掉到600+.... 然后...估计得绿名了.. sad A.I Wanna Be the Guy 题意:让你判断1-n个数哪个数没有出现.. sb题 ...

  4. Codeforces Round #545 (Div. 1) 简要题解

    这里没有翻译 Codeforces Round #545 (Div. 1) T1 对于每行每列分别离散化,求出大于这个位置的数字的个数即可. # include <bits/stdc++.h&g ...

  5. Codeforces Round #524 (Div. 2)(前三题题解)

    这场比赛手速场+数学场,像我这样读题都读不大懂的蒟蒻表示呵呵呵. 第四题搞了半天,大概想出来了,但来不及(中途家里网炸了)查错,于是我交了两次丢了100分.幸亏这次没有掉rating. 比赛传送门:h ...

  6. Codeforces Round #624 (Div. 3)(题解)

    Codeforces Round #624 (Div.3) 题目地址:https://codeforces.ml/contest/1311 B题:WeirdSort 题意:给出含有n个元素的数组a,和 ...

  7. Codeforces Round #253 (Div. 1) (A, B, C)

    Codeforces Round #253 (Div. 1) 题目链接 A:给定一些牌,然后如今要提示一些牌的信息,要求提示最少,使得全部牌能够被分辨出来. 思路:一共2^10种情况,直接暴力枚举,然 ...

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

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

  9. Codeforces Round #545 (Div. 1)

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

随机推荐

  1. DB9 ------ 接口定义

    下图是母座和公座的接口定义: 特别提醒:以上是公座和母座的接口定义,如果是串口线,RXD就变成TXD,以此类推.

  2. python机器学习-sklearn挖掘乳腺癌细胞(三)

    python机器学习-sklearn挖掘乳腺癌细胞( 博主亲自录制) 网易云观看地址 https://study.163.com/course/introduction.htm?courseId=10 ...

  3. JAVA核心技术I---JAVA基础知识(函数)

    一:自定义函数 由于JAVA中都是由类组成,所以想实现类似于函数的功能,直接使用main主函数进行调用,就需要使用静态类方法,直接调用,而不需要实例对象 public class HelloWorld ...

  4. netty的HelloWorld演示

    pom <dependency> <groupId>io.netty</groupId> <artifactId>netty-all</artif ...

  5. Web API中的返回值类型

    WebApi中的返回值类型大致可分为四种: Void/ IHttpActionResult/ HttpResponseMessage /自定义类型 一.Void void申明方法没有返回值,执行成功后 ...

  6. 【英文文档】Solidifier for Windows Installation Guide

    Page 1Solidifier for Windows  Installation Guide Page 2McAfee, Inc.McAfee® Solidifier for Windows In ...

  7. 剑指offer面试题4: 二维数组中的查找

    题目描述 在一个二维数组中(每个一维数组的长度相同),每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序.请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数 ...

  8. Oracle和Mysql的安装

    Oracle12C的安装:https://blog.csdn.net/qubeleyz/article/details/79451192 Mysql安装:

  9. Kafka安装部署

    1.从官网下载安装包,并通过Xftp5上传到机器集群上    下载kafka_2.11-1.1.0.tgz版本,并通过Xftp5上传到hadoop机器集群的第一个节点node1上的/opt/uploa ...

  10. ArcGis Python脚本——ArcGIS 中使用的 Python 是什么版本

    Python 编程语言用于自 9.0 起的各版本 ArcGIS 中,并被整合到 ArcMap 和 ArcGIS for Server 的自动安装中. ArcGIS 将在完整安装过程中安装下列 Pyth ...