CodeForces #307 Div.2 B. ZgukistringZ
来源:互联网 发布:我的世界linux启动器 编辑:程序博客网 时间:2024/05/19 04:55
B. ZgukistringZ
题目连接:http://codeforces.com/problemset/problem/551/B
题意:给出3个字符串a,b,c,要求改变字符串a中的字符顺序,使得可以出现的字符串b和字符串c出现的次数最多.
题解:先匹配字符串b,枚举字符串a中出现字符串b的最多次数,然后从剩余的字符串中匹配字符串c,最后按字母序输出剩下的串。
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int counta[30], countb[30], countc[30];const int MAX = 1e5+5;int main() { char a[MAX],b[MAX],c[MAX]; while(gets(a)) { gets(b); gets(c); int lena = strlen(a); int lenb = strlen(b); int lenc = strlen(c); memset(counta, 0, sizeof(counta)); memset(countb, 0, sizeof(countb)); memset(countc, 0, sizeof(countc)); for(int i = 0; i < lena; i++) counta[ a[i] - 'a' ] ++; for(int i = 0; i < lenb; i++) countb[ b[i] - 'a' ] ++; for(int i = 0; i < lenc; i++) countc[ c[i] - 'a' ] ++; int ans = 1e8; for(int i = 0; i < 26; i++) if(countb[i]) ans = min(ans, counta[i] / countb[i]); int ansb = 0, ansc = 0; for(int i = 0; i <= ans; i++) { int cnt = 1e8; for(int j = 0; j < 26; j++) if(countc[j]) cnt = min(cnt, (counta[j] - countb[j] * i) / countc[j]); if(i + cnt > ansb + ansc) { ansb = i; ansc = cnt; } } for(int i = 0; i < ansb; i++) printf("%s",b); for(int i = 0; i < ansc; i++) printf("%s",c); for(int i = 0; i < 26; i++) for(int j = 0; j < counta[i] - countb[i] * ansb - countc[i] * ansc; j++) { printf("%c", i + 'a'); } printf("\n"); } return 0;}
0 0
- Codeforces Round #307 (Div. 2) B. ZgukistringZ
- CodeForces #307 Div.2 B. ZgukistringZ
- Codeforces Round #307 (Div. 2) B. ZgukistringZ (贪心 + 暴力)
- [字符串]Codeforces Round #307 (Div. 2) B.ZgukistringZ
- B. ZgukistringZ-简单字符串处理-Codeforces Round #307 (Div. 2)
- codeforces #307 B. ZgukistringZ(枚举+计数)
- codeforces 552B ZgukistringZ
- codeforces 551B ZgukistringZ
- Codeforces 551B ZgukistringZ
- 交换a串的位置让b.c串出现最多次 暴力 Codeforces Div. 2 B. ZgukistringZ
- 【19.46%】【codeforces 551B】ZgukistringZ
- Codeforces 551B ZgukistringZ (字符串处理)
- Codeforces 551B ZgukistringZ【思维+枚举】
- Codeforces Round #307 (Div. 2) A、B
- Codeforces Round #307 (Div. 2) B C
- Codeforces #261 Div 2 B
- codeforces #368 div.2B
- Codeforces--477Div.2--B
- 简单使用URLConnection、HttpURLConnection和HttpClient访问网络资源
- wireshark 实用过滤表达式(针对ip、协议、端口、长度和内容)
- java再复习-常用线程池
- 采用stack实现的文件夹循环深度优先遍历的基类
- Maven基础学习—Maven入门
- CodeForces #307 Div.2 B. ZgukistringZ
- Android酷炫实用的开源框架(UI框架)
- A页面跳转到B页面某一指定位置
- 射频识别技术漫谈(7)——ID卡
- 侧边栏的实现(三)
- 类方法、静态方法、属性
- node.js学习(五、基础js语法)
- sublime text 2 安装 xdebug
- 微信支付