题目传送门

 /*
题意:任意排列第一个字符串,使得有最多的不覆盖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. hash_map与unordered_map区别

    http://blog.csdn.net/blues1021/article/details/45054159

  2. JSP中过滤器的设置

    JSP中过滤器的设置 package com.filter; import java.io.IOException; import java.net.URLDecoder; import java.u ...

  3. 微信小程序之 SideBar(侧栏分类)

    项目目录: 模拟数据: utils / data.js function getSData() { var data = [ { "id": 1, "tree" ...

  4. AFNetworking配合Swift3.0请求数据

    首先用桥接或pods将AFNetworking导入项目,在这不再赘述,然后创建一个单例NetWorkTools.swift 继承:AFHTTPSessionManager import UIKit i ...

  5. Linux程序设计(搭建开发环境--curses)

    看官们.咱们今天要说的内容.是前面内容的一点小补充,详细的内容是:安装curses开发包.以搭建 开发环境.闲话休说,言归正转. 我们在前面说过搭建开发环境的内容,主要说了开发环境中的GCC和VIM, ...

  6. cmake使用演示样例与整理总结

    本文代码托管于github  cmake_demo cmake中一些提前定义变量 PROJECT_SOURCE_DIR project的根文件夹 PROJECT_BINARY_DIR 执行cmake命 ...

  7. Redhat enterpise6 安装unix2dos/dos2unix

    初用unix2dos,在rhel6 上 用yum install unix2dos , 提示源不可用, 那好吧, 就去rpm包网:http://rpm.pbone.net/ 下载了一个unix2dos ...

  8. Trie(前缀树)和ternary trie和binary search tree

    1 什么是trie trie是一棵多叉树,假如存放的是由26个字母(不区分大小写)构成的字符串的话,那么就是一棵26叉树. trie树是一棵前缀树,因为每个结点只保存字符串中的一个字符,整个字符串保存 ...

  9. wget和curl

    1 curl比wget支持更多的协议 2 wget是支持递归的,而curl不支持

  10. 8088汇编跳转和PSW状态字寄存器

    DDD 8088 汇编跳转 日期:2003年6月12日  出处:嬴政天下整理收藏  作者:看雪  人气: 8735 8088 汇编跳转 一.状态寄存器 PSW(Program Flag)程序状态字寄存 ...