字符串处理/贪心 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 ...
随机推荐
- 202. Segment Tree Query
最后更新 二刷 09-Jan-17 正儿八经线段树的应用了. 查找区间内的值. 对于某一个Node,有这样的可能: 1)需要查找区间和当前NODE没有覆盖部分,那么直接回去就行了. 2)有覆盖的部分, ...
- django 简易博客开发 2 模板和数据查询
首先还是贴一下项目地址 https://github.com/goodspeedcheng/sblog 因为代码全在上面 上一篇博客我们介绍了 django的安装配置,新建project,新建a ...
- Hexo搭建个人blog
Hexo搭建 现在只想说心累... 前几天看了几个牛人的blog,感觉他们的风格很舒服,然后就发现了Hexo这个好东西!激动的想马上自己也弄一个,昨天晚上开始看资料特别是:潘柏信写了两篇 HEXO搭建 ...
- centos 5.11修改ssh默认端口号
查看下服务器端口号范围: # sysctl -a|grep ip_local_port_range net.ipv4.ip_local_port_range = 32768 61000 新 ...
- 分享codeigniter框架,在zend studio 环境下的代码提示
一.到github下载相关文件 https://github.com/Stunt/Codeigniter-autocomplete 二.把文件放到application/config中 代码提示就出来 ...
- 《modern operating system》 chapter 6 DEADLOCKS 笔记
DEADLOCKS Both processes are blocked and will remain so forever. This situation is called a deadlock ...
- Jedis学习使用(java操作redis)
Jedis 是 Redis 官方首选的 Java client开发包. 工作过程总结的一个演示样例.贴出来,例如以下: package com.wujintao.redis; import java. ...
- NDK编程中如何在C文件中打印调试信息
1,在Android.mk文件中加上 LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog LOCAL_PATH := $(call my-dir)include ...
- 自己动手写最简单的Android驱动---LED驱动的编写【转】
本文转载自:http://blog.csdn.net/k_linux_man/article/details/7023824 转载注明出处,作者:K_Linux_Man, 薛凯 山东中医药大学,给文章 ...
- android编译打包(用ant脚本打包)
为了可以实现自动化打包,下面我介绍一下如何用ant工具来打包android项目: 直接上build.xml文件源码: <?xml version="1.0"?> < ...