题目链接: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. 2. github创建 git仓库,克隆,拉取和推送操作(所有的git命令前提是一定在当前项目目录下)

    步骤: 1.点击小猫,回到初始页面 2.点击start a project,首先会出现一个验证email地址(我们注册的时候,有一个email输入,进去邮箱验证一下) 3.重新点击start a pr ...

  2. typedef typename的用法

    我自己最后在这篇文章里理解:[C++]typedef typename什么意思? typedef typename A::a_type b_type; 其中typename是告诉编译器A::a_typ ...

  3. java和c#值类型和引用类型

    java数据类型分为基本数据类型和引用类型 基本数据类型:int  float  double  bool  char byte 引用数据类型:string  array  class interfa ...

  4. POJ 2528 Mayor's posters (线段树+离散化)

    Mayor's posters Time Limit: 1000MS   Memory Limit: 65536K Total Submissions:75394   Accepted: 21747 ...

  5. xlrd(excel导入mysql数据库)

    一.xlrd模块: python 对 excel 文件进行读操作 1.下载xlrd 并安装 http://pypi.python.org/pypi/xlrd wget https://pypi.pyt ...

  6. 1411 - Ants(巨人与鬼)

    参考博客 紫薯P230 题意:给出平面上n个白点n个黑点,要求两两配对,且配对所连线段没有交点. 紫薯思路:找出y坐标最小的点,如果多个,考虑x最小的.将其他点相对于这个点按极角从小到大排序,然后开始 ...

  7. 2017-12-18python全栈9期第三天第四节之str的索引与切片

    #!/user/bin/python# -*- coding:utf-8 -*-s = 'zdlswwzl's1 = s[0]print(s1)s2 = s[-1]print(s2)s3 = s[0: ...

  8. saltstack syndic

    #syndic 相当于master的代理,master通过syndic代理控制node主机 master <------ syndic+master <---------- node ma ...

  9. python django基础三 模版渲染

    request对象 当一个页面被请求时,Django就会创建一个包含本次请求原信息的HttpRequest对象.Django会将这个对象自动传递给响应的视图函数,一般视图函数约定俗成地使用 reque ...

  10. Web API中给领域模型添加媒体类型支持

    一.媒体类型 媒体类型(也称为MIME类型)标识一段数据的格式.在HTTP中,媒体类型描述了消息体的格式.媒体类型由两个字符串组成,一个类型和一个子类型.例如:text / html: image/ ...