字符串处理/贪心 Codeforces Round #307 (Div. 2) B. ZgukistringZ
题目传送门
/*
题意:任意排列第一个字符串,使得有最多的不覆盖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的更多相关文章
- Codeforces Round #307 (Div. 2) B. ZgukistringZ 暴力
B. ZgukistringZ Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/551/probl ...
- 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 ...
- 水题 Codeforces Round #307 (Div. 2) A. GukiZ and Contest
题目传送门 /* 水题:开个结构体,rk记录排名,相同的值有相同的排名 */ #include <cstdio> #include <cstring> #include < ...
- 贪心 Codeforces Round #303 (Div. 2) B. Equidistant String
题目传送门 /* 题意:找到一个字符串p,使得它和s,t的不同的总个数相同 贪心:假设p与s相同,奇偶变换赋值,当是偶数,则有答案 */ #include <cstdio> #includ ...
- 贪心 Codeforces Round #288 (Div. 2) B. Anton and currency you all know
题目传送门 /* 题意:从前面找一个数字和末尾数字调换使得变成偶数且为最大 贪心:考虑两种情况:1. 有偶数且比末尾数字大(flag标记):2. 有偶数但都比末尾数字小(x位置标记) 仿照别人写的,再 ...
- 贪心 Codeforces Round #301 (Div. 2) B. School Marks
题目传送门 /* 贪心:首先要注意,y是中位数的要求:先把其他的都设置为1,那么最多有(n-1)/2个比y小的,cnt记录比y小的个数 num1是输出的1的个数,numy是除此之外的数都为y,此时的n ...
- 贪心 Codeforces Round #297 (Div. 2) C. Ilya and Sticks
题目传送门 /* 题意:给n个棍子,组成的矩形面积和最大,每根棍子可以-1 贪心:排序后,相邻的进行比较,若可以读入x[p++],然后两两相乘相加就可以了 */ #include <cstdio ...
- 贪心 Codeforces Round #304 (Div. 2) B. Soldier and Badges
题目传送门 /* 题意:问最少增加多少值使变成递增序列 贪心:排序后,每一个值改为前一个值+1,有可能a[i-1] = a[i] + 1,所以要 >= */ #include <cstdi ...
- 找规律/贪心 Codeforces Round #310 (Div. 2) A. Case of the Zeros and Ones
题目传送门 /* 找规律/贪心:ans = n - 01匹配的总数,水 */ #include <cstdio> #include <iostream> #include &l ...
随机推荐
- IOS开发 Block的学习
苹果公司正在大力推广Block块语法的使用,据说Block会迟早取代一般协议代理的使用. Block最大的作用是函数回调,简化代码. 在ios中,将blocks当成对象来处理,它封装了一段代码,这段代 ...
- XMLHttpRequest对象解读
<!DOCTYPE html> <html> <body> <script> function reqListener () { console.log ...
- influxDB系列(二)
来源于我在一个influxDB的qq交流群中的提问, 然后有个人 提了一个问题---->触发了我的思考!! :) 哈哈 自己的每一次说出一个回答,都是一次新的思考,也都进行了一些查阅资料,思考, ...
- Java知识图谱
1.Java学习路径1 我想很多人看到这个路径可能会问我在哪里可以学习,所以就先附上这条路径的学习地址吧,这也是这张图片的来源,愿意学习的可以去看看:Java研发工程师学习路径 2.Java学习路径2 ...
- arcgis 发布地图服务
arcgis中,地图文档需要发布,才能为WEB所用. 咋发布呢? 1.在arcmap里面,点击 文件 - 共享为 - 服务 2.在弹出的对话框里选"发布服务",然后 3.这里面有点 ...
- How can I pass data from Flask to JavaScript in a template?
https://stackoverflow.com/questions/11178426/how-can-i-pass-data-from-flask-to-javascript-in-a-templ ...
- Deep Learning 29: caffe入门学习
1.跑教程:深度学习(六)caffe入门学习,上面有比较好的注释 .prototxt文件:网络结构文件 solver.prototxt:网络求解文件 net: "examples/mnist ...
- iOS SHA加密算法的实现
- (NSString *)SHAStringWithSourceData:(NSData *)data type:(SHAType)type{ int shaDigestLength; switch ...
- js控制页面显示
两个菜单切换显示页面内容: js控制代码, /** JS初始化 **/ $(document).ready(function() { $('#email_btn').click(function(){ ...
- Lightoj 1009 - Back to Underworld
1009 - Back to Underworld PDF (English) Statistics Forum Time Limit: 4 second(s) Memory Limit: 32 ...