题目链接: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. Educational Codeforces Round 53 (Rated for Div. 2)

    http://codeforces.com/contest/1073 A. Diverse Substring #include <bits/stdc++.h> using namespa ...

  2. plink:ped格式转换为bed格式

    命令行如下: plink --file FILENAME --make-bed --out FILENAME 第一个FILENAME的后缀为.ped和.map,生成的第二个FILENAME的后缀为.b ...

  3. Tree Restoration Gym - 101755F (并查集)

    There is a tree of n vertices. For each vertex a list of all its successors is known (not only direc ...

  4. Tennis Game CodeForces - 496D(唯一分解定理,费马大定理)

    Tennis Game CodeForces - 496D 通过排列组合解决问题. 首先两组不同素数的乘积,是互不相同的.这应该算是唯一分解定理的逆运用了. 然后是,输入中的素数,任意组合,就是n的因 ...

  5. (map string)Crazy Search hdu1381

    Crazy Search Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  6. MyBatis-generator-Maven方式

    一.配置依赖 1.依赖信息 pom.xml <?xml version="1.0" encoding="UTF-8"?> <project x ...

  7. java 写一个 map reduce 矩阵相乘的案例

    1.写一个工具类用来生成 map reduce 实验 所需 input 文件 下面两个是原始文件 matrix1.txt 1 2 -2 0 3 3 4 -3 -2 0 2 3 5 3 -1 2 -4 ...

  8. 【转载】C# List用法 List介绍

    https://www.cnblogs.com/dyhao/p/9501479.html

  9. GeoGlobe Server运维

    本篇博文简单记录鄙人在管理和维护GeoGlobe Server中,遇到的一些问题以及可行的解决方案 1 关于启动内存 Server默认的启动内存是256M,当服务比较多的时候,启动就会很慢.我们可以修 ...

  10. 启动aspx文件错误

    有一次,为了模仿翻页效果,设置的启动也是aspx文件.当时因为重装系统的原因,我的系统暂时不支持aspx文件的发布访问.所以,我就在MIME Type里面添加了对aspx文件的访问,如下图: 这样就可 ...