Professor GukiZ doesn't accept string as they are. He likes to swap some letters in string to obtain a new one.

GukiZ has strings ab,
and c. He wants to obtain string k by
swapping some letters in a, so that k should
contain as many non-overlapping substrings equal either to b or c as
possible. Substring of string x is a string formed by consecutive segment of characters from x.
Two substrings of string x overlap if there is position i in
string x occupied by both of them.

GukiZ was disappointed because none of his students managed to solve the problem. Can you help them and find one of possible strings k?

Input

The first line contains string a, the second line contains string b,
and the third line contains string c (1 ≤ |a|, |b|, |c| ≤ 105,
where |s|denotes the length of string s).

All three strings consist only of lowercase English letters.

It is possible that b and c coincide.

Output

Find one of possible strings k, as described in the problem statement. If there are multiple possible answers, print any of them.

Sample test(s)
input
aaa
a
b
output
aaa
input
pozdravstaklenidodiri
niste
dobri
output
nisteaadddiiklooprrvz
input
abbbaaccca
ab
aca
output
ababacabcc
Note

In the third sample, this optimal solutions has three non-overlaping substrings equal to either b or c on
positions 1 – 2 (ab), 3 – 4 (ab),5 – 7 (aca).
In this sample, there exist many other optimal solutions, one of them would be acaababbcc.

这题因为字母可以随意调换,所以先数出a,b,c三个字符串所有字母表中的字母的个数,然后看最多能填充多少个b字符串minx,然后填充0~minx个字符串,再看在当前情况下能填充多少个c字符串,计算最大值。

#include<stdio.h>
#include<string.h>
char s1[100006],s2[100006],s3[100006];
int a[30],b[30],c[30],a1[30];
int main()
{
int n,m,i,j,len1,len2,len3,minx1,minx2,maxx,minx,t1,t2;
while(scanf("%s",s1)!=EOF)
{
scanf("%s%s",s2,s3);
len1=strlen(s1);
len2=strlen(s2);len3=strlen(s3);
memset(a,0,sizeof(a));memset(b,0,sizeof(b));memset(c,0,sizeof(c));memset(a1,0,sizeof(a1));
for(i=0;i<len1;i++){
a[s1[i]-'a']++;a1[s1[i]-'a']++;
}
for(i=0;i<len2;i++){
b[s2[i]-'a']++;
}
for(i=0;i<len3;i++){
c[s3[i]-'a']++;
}
minx1=200006;
for(i=0;i<=25;i++){
if(b[i]==0)continue;
if(minx1>(a[i]/b[i]))minx1=a[i]/b[i];
}
minx2=200006;
for(i=0;i<=25;i++){
if(c[i]==0)continue;
if(minx2>(a[i]/c[i]))minx2=a[i]/c[i];
}
maxx=minx2;t1=0;t2=minx2;
for(i=1;i<=minx1;i++){
minx=200006;
for(j=0;j<=25;j++){
a[j]-=b[j];
}
for(j=0;j<=25;j++){
if(c[j]==0)continue;
if(minx>(a[j]/c[j]))minx=a[j]/c[j];
}
if(maxx<minx+i){
maxx=minx+i;
t1=i;t2=minx;
}
}
for(i=1;i<=t1;i++)printf("%s",s2);
for(i=1;i<=t2;i++)printf("%s",s3);
for(i=0;i<=25;i++){
a1[i]=a1[i]-t1*b[i]-t2*c[i];
for(j=1;j<=a1[i];j++){
printf("%c",'a'+i);
}
}
printf("\n");
}
return 0;
}

Codeforces Round #307 (Div. 2) B. ZgukistringZ的更多相关文章

  1. 字符串处理/贪心 Codeforces Round #307 (Div. 2) B. ZgukistringZ

    题目传送门 /* 题意:任意排列第一个字符串,使得有最多的不覆盖a/b字符串出现 字符串处理/贪心:暴力找到最大能不覆盖的a字符串,然后在b字符串中动态得出最优解 恶心死我了,我最初想输出最多的a,再 ...

  2. Codeforces Round #307 (Div. 2) B. ZgukistringZ 暴力

    B. ZgukistringZ Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/551/probl ...

  3. 水题 Codeforces Round #307 (Div. 2) A. GukiZ and Contest

    题目传送门 /* 水题:开个结构体,rk记录排名,相同的值有相同的排名 */ #include <cstdio> #include <cstring> #include < ...

  4. 「日常训练」ZgukistringZ(Codeforces Round #307 Div. 2 B)

    题意与分析(CodeForces 551B) 这他妈哪里是日常训练,这是日常弟中弟. 题意是这样的,给出一个字符串A,再给出两个字符串B,C,求A中任意量字符交换后(不限制次数)能够得到的使B,C作为 ...

  5. Codeforces Round #307 (Div. 2) E. GukiZ and GukiZiana 分块

    E. GukiZ and GukiZiana Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/55 ...

  6. Codeforces Round #307 (Div. 2) C. GukiZ hates Boxes 贪心/二分

    C. GukiZ hates Boxes Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/551/ ...

  7. Codeforces Round #307 (Div. 2) A. GukiZ and Contest 水题

    A. GukiZ and Contest Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/551/ ...

  8. Codeforces Round #307 (Div. 2) D. GukiZ and Binary Operations (矩阵高速幂)

    题目地址:http://codeforces.com/contest/551/problem/D 分析下公式能够知道,相当于每一位上放0或者1使得最后成为0或者1.假设最后是0的话,那么全部相邻位一定 ...

  9. Codeforces Round #307 (Div. 2) E. GukiZ and GukiZiana (分块)

    题目地址:http://codeforces.com/contest/551/problem/E 将n平均分成sqrt(n)块,对每一块从小到大排序,并设置一个总体偏移量. 改动操作:l~r区间内,对 ...

随机推荐

  1. 【Java】流程控制 - 顺序结构、 选择(分支)结构(单分支、双分支、多分支、嵌套)、循环结构(for、while、do...while)、跳转语句(break、continue)

    流程控制语句结构 文章目录 流程控制语句结构 一. 顺序结构 1. 输出语句 2. 输入语句 3.code 二.复合语句 三. 分支结构 1. 条件判断 1.单分支结构 2.双分支结构 3.多分支结构 ...

  2. ptgmk

    num >= 1125899906842624 ? "P" \ : num >= 1099511627776 ? "T" \ : num >= ...

  3. 【Problems】Could not set property 'id' of 'xxx' with value '' Cause argument type mismatch

    一个问题:向comment表添加记录时,报错, 无法设置值. reflection.ReflectionException: Could not set property 'id' of 'class ...

  4. python sqlite3增加表字段

    给sqlite3表格增加新字段,要注意大小写,要不然不成功. 一开始这样写,不成功! 后面规范写,按大小写严格规范写! 成功了!现在查看新增加的字段commit: 仔细看,这下全部小写,括表名称.co ...

  5. JMS监听Oracle AQ

    该文档中,oracle版本为11g,jdk版本1.8,java项目为maven构建的springboot项目,springboot的版本为2.1.6,并使用了定时任务来做AQ监听的重连功能,解决由于外 ...

  6. VKM5对应的BAPI或者函数

    在业务上,当一个交货单创建后,可能需要使用事物VKM5进行批准(解冻)才能做后续的捡配,发货过账等操作,通过搜索引擎发现,很多人也都会问是否有对应的bapi或者函数,替代VKM5,能够自开发程序进行批 ...

  7. Spring Aop中四个重要概念,切点,切面,连接点,通知

    1. 通知: 就是我们编写的希望Aop时执行的那个方法.我们通过Aop希望我们编写的方法在目标方法执行前执行,或者执行后执行.2. 切点:切点就是我们配置的满足我们条件的目标方法.比如我们规定:名字前 ...

  8. JS中常用的工具类

    一.日期工具类 /** * 日期时间工具类 * @type {{dateFormat}} */ var DateTime = function () { var patterns = { PATTER ...

  9. unity3D进阶

    前言 在之前的例子中,我们都没有用到unity的精髓,例如地形系统.物理系统.粒子系统等,本文记录unity3D的进阶简单应用 前期准备 https://unity.cn/releases/full/ ...

  10. 每月一更的《HelloGitHub》第 58 期,来啦!

    HelloGitHub 分享 GitHub 上有趣.入门级的开源项目.欢迎大家: 贡献代码 宣传你觉得优秀的项目 Star 项目️ 本月刊是每月 28 号更新,再见月刊就是年后了.在这里提前祝大家:新 ...