题目传送门

 /*
题意:任意排列第一个字符串,使得有最多的不覆盖a/b字符串出现
字符串处理/贪心:暴力找到最大能不覆盖的a字符串,然后在b字符串中动态得出最优解
恶心死我了,我最初想输出最多的a,再最多的b,然而并不能保证是最多的:(
*/
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std; const int MAXN = 1e5 + ;
const int INF = 0x3f3f3f3f;
char s[MAXN], a[MAXN], b[MAXN];
int cnt_s[], cnt_a[], cnt_b[];
int len_s, len_a, len_b; int main(void) //Codeforces Round #307 (Div. 2) B. ZgukistringZ
{
// freopen ("B.in", "r", stdin); while (scanf ("%s", s) == )
{
scanf ("%s", a); scanf ("%s", b);
len_s = strlen (s); len_a = strlen (a); len_b = strlen (b); memset (cnt_s, , sizeof (cnt_s));
memset (cnt_a, , sizeof (cnt_a));
memset (cnt_b, , sizeof (cnt_b)); for (int i=; i<len_s; ++i) cnt_s[s[i]-'a']++;
for (int i=; i<len_a; ++i) cnt_a[a[i]-'a']++;
for (int i=; i<len_b; ++i) cnt_b[b[i]-'a']++; int ans_a = , ans_b = ; int tot = ;
for (int i=; i<; ++i) {if (cnt_a[i]) tot = min (tot, cnt_s[i] / cnt_a[i]);}
for (int i=; i<=tot; ++i)
{
int p = ;
for (int j=; j<; ++j) {if (cnt_b[j]) p = min (p, (cnt_s[j] - i * cnt_a[j]) / cnt_b[j]);}
if (i + p > ans_a + ans_b) {ans_a = i; ans_b = p;}
} for (int i=; i<=ans_a; ++i) printf ("%s", a);
for (int j=; j<=ans_b; ++j) printf ("%s", b);
for (int i=; i<; ++i)
{
for (int j=; j<=cnt_s[i]-ans_a*cnt_a[i]-ans_b*cnt_b[i]; ++j)
printf ("%c", 'a' + i);
}
puts ("");
} return ;
}

字符串处理/贪心 Codeforces Round #307 (Div. 2) B. ZgukistringZ的更多相关文章

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

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

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

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

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

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

  4. 贪心 Codeforces Round #303 (Div. 2) B. Equidistant String

    题目传送门 /* 题意:找到一个字符串p,使得它和s,t的不同的总个数相同 贪心:假设p与s相同,奇偶变换赋值,当是偶数,则有答案 */ #include <cstdio> #includ ...

  5. 贪心 Codeforces Round #288 (Div. 2) B. Anton and currency you all know

    题目传送门 /* 题意:从前面找一个数字和末尾数字调换使得变成偶数且为最大 贪心:考虑两种情况:1. 有偶数且比末尾数字大(flag标记):2. 有偶数但都比末尾数字小(x位置标记) 仿照别人写的,再 ...

  6. 贪心 Codeforces Round #301 (Div. 2) B. School Marks

    题目传送门 /* 贪心:首先要注意,y是中位数的要求:先把其他的都设置为1,那么最多有(n-1)/2个比y小的,cnt记录比y小的个数 num1是输出的1的个数,numy是除此之外的数都为y,此时的n ...

  7. 贪心 Codeforces Round #297 (Div. 2) C. Ilya and Sticks

    题目传送门 /* 题意:给n个棍子,组成的矩形面积和最大,每根棍子可以-1 贪心:排序后,相邻的进行比较,若可以读入x[p++],然后两两相乘相加就可以了 */ #include <cstdio ...

  8. 贪心 Codeforces Round #304 (Div. 2) B. Soldier and Badges

    题目传送门 /* 题意:问最少增加多少值使变成递增序列 贪心:排序后,每一个值改为前一个值+1,有可能a[i-1] = a[i] + 1,所以要 >= */ #include <cstdi ...

  9. 找规律/贪心 Codeforces Round #310 (Div. 2) A. Case of the Zeros and Ones

    题目传送门 /* 找规律/贪心:ans = n - 01匹配的总数,水 */ #include <cstdio> #include <iostream> #include &l ...

随机推荐

  1. JAVA学习(一):Java介绍及其平台、开发环境的配置与搭建

    Java介绍及其平台.开发环境的配置与搭建 1.Java的介绍 Java是一种面向对象的编程语言,具有跨平台.可移植.分布式.简单.可扩展等诸多特性.Java能够进行桌面应用.Web应用.分布式系统及 ...

  2. leetCode 67.Add Binary (二进制加法) 解题思路和方法

    Given two binary strings, return their sum (also a binary string). For example, a = "11" b ...

  3. 【机器学习具体解释】SVM解二分类,多分类,及后验概率输出

    转载请注明出处:http://blog.csdn.net/luoshixian099/article/details/51073885 CSDN−勿在浮沙筑高台 支持向量机(Support Vecto ...

  4. Maven实战(七,八)——经常使用Maven插件介绍

    我们都知道Maven本质上是一个插件框架,它的核心并不运行不论什么详细的构建任务,全部这些任务都交给插件来完毕,比如编译源代码是由maven-compiler-plugin完毕的.进一步说,每一个任务 ...

  5. slice,substr,substring的区别

    <!DOCTYPE html> <!-- To change this license header, choose License Headers in Project Prope ...

  6. XML转换为HTML

    from:http://www.w3school.com.cn/xml/xml_to_html.asp 在上一节中,我们讲解了如何通过 JavaScript 来解析 XML 并访问 DOM. 本例遍历 ...

  7. windows下使用mingw和msys编译GOTOBLAS和OpenBLAS

    在windows下利用msys编译openBLAS若遇到错误提示: gcc: CreateProcess : No such file or directory 问题原因参考:http://www.c ...

  8. (转载)synchronized代码块

    原文:http://blog.csdn.net/luoweifu/article/details/46613015 作者:luoweifu 转载请标名出处 <编程思想之多线程与多进程(1)——以 ...

  9. USACO35 翻转奶牛(尺取法)

    通过这道题了解了不少有关翻转的知识呢...... 首先,我们枚举翻转的区间长度k,假设i有个按钮,按下就可以让i~i+k-1翻转,那就有两个状态,按i或不按i(因为按两次相当于没按),那就往后扫一遍, ...

  10. YTU 2895: H--唱歌的鸟儿

    2895: H--唱歌的鸟儿 时间限制: 1 Sec  内存限制: 128 MB 提交: 26  解决: 10 题目描述 烟大东门有一棵大杨树,树上经常会有很多鸟儿飞来飞去.春天来了,学生物的小姜发现 ...