codeforces 551B
2015-06-15 13:57
281 查看
题意就是给三个字符串。。。问一最多能凑成几个二和三,,,
凑成了就输出没凑成的剩下的随便按照字典序输出就好了。。。。。
比赛的时候我想难了我去,,,,,,
题应该就是寻找字符串1能整出来几个2,,,,,储存所有字母的数量,,,,看2有的哪个1最少就是几个1,,,,(完全暴力也是不行的,,,,)然后把3的字符也都储存起来,,,,每个点分别看2+3的极值能取到多少,,,,还有3本身的能取到多少,,,,,,,然后就完事了。。。。。。。。。。。比赛的时候智商完全没有好吗?
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
const int INF = 0x3f3f3f3f;
char s[MAXN], a[MAXN], b[MAXN];
int cnt_s[30], cnt_a[30], cnt_b[30];
int len_s, len_a, len_b;
int main(void)
{
while (scanf ("%s", s) == 1)
{
scanf ("%s", a); scanf ("%s", b);
len_s = strlen (s); len_a = strlen (a); len_b = strlen (b);
memset (cnt_s, 0, sizeof (cnt_s));
memset (cnt_a, 0, sizeof (cnt_a));
memset (cnt_b, 0, sizeof (cnt_b));
for (int i=0; i<len_s; ++i) cnt_s[s[i]-'a']++;
for (int i=0; i<len_a; ++i) cnt_a[a[i]-'a']++;
for (int i=0; i<len_b; ++i) cnt_b[b[i]-'a']++;
int ans_a = 0, ans_b = 0; int tot = 100000;
for (int i=0; i<30; ++i) {if (cnt_a[i]) tot = min (tot, cnt_s[i] / cnt_a[i]);}
for (int i=0; i<=tot; ++i)
{
int p = 100000;
for (int j=0; j<30; ++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=1; i<=ans_a; ++i) printf ("%s", a);
for (int j=1; j<=ans_b; ++j) printf ("%s", b);
for (int i=0; i<30; ++i)
{
for (int j=1; j<=cnt_s[i]-ans_a*cnt_a[i]-ans_b*cnt_b[i]; ++j)
printf ("%c", 'a' + i);
}
puts ("");
}
return 0;
}
就是这样,,,,,,想不到没做出来。。哎。。。。。。。。
凑成了就输出没凑成的剩下的随便按照字典序输出就好了。。。。。
比赛的时候我想难了我去,,,,,,
题应该就是寻找字符串1能整出来几个2,,,,,储存所有字母的数量,,,,看2有的哪个1最少就是几个1,,,,(完全暴力也是不行的,,,,)然后把3的字符也都储存起来,,,,每个点分别看2+3的极值能取到多少,,,,还有3本身的能取到多少,,,,,,,然后就完事了。。。。。。。。。。。比赛的时候智商完全没有好吗?
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
const int INF = 0x3f3f3f3f;
char s[MAXN], a[MAXN], b[MAXN];
int cnt_s[30], cnt_a[30], cnt_b[30];
int len_s, len_a, len_b;
int main(void)
{
while (scanf ("%s", s) == 1)
{
scanf ("%s", a); scanf ("%s", b);
len_s = strlen (s); len_a = strlen (a); len_b = strlen (b);
memset (cnt_s, 0, sizeof (cnt_s));
memset (cnt_a, 0, sizeof (cnt_a));
memset (cnt_b, 0, sizeof (cnt_b));
for (int i=0; i<len_s; ++i) cnt_s[s[i]-'a']++;
for (int i=0; i<len_a; ++i) cnt_a[a[i]-'a']++;
for (int i=0; i<len_b; ++i) cnt_b[b[i]-'a']++;
int ans_a = 0, ans_b = 0; int tot = 100000;
for (int i=0; i<30; ++i) {if (cnt_a[i]) tot = min (tot, cnt_s[i] / cnt_a[i]);}
for (int i=0; i<=tot; ++i)
{
int p = 100000;
for (int j=0; j<30; ++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=1; i<=ans_a; ++i) printf ("%s", a);
for (int j=1; j<=ans_b; ++j) printf ("%s", b);
for (int i=0; i<30; ++i)
{
for (int j=1; j<=cnt_s[i]-ans_a*cnt_a[i]-ans_b*cnt_b[i]; ++j)
printf ("%c", 'a' + i);
}
puts ("");
}
return 0;
}
就是这样,,,,,,想不到没做出来。。哎。。。。。。。。
相关文章推荐
- Javascript所有数组方法(forEach,some,every,join,concat等等)
- 6.15 喜刷刷1 oj 数组输出
- Ubuntu14.04使用VNC无法显示图形界面问题的解决
- 0. Redis-Server(操作)
- Do not expose your watch to make electricity or magnets
- Android学习笔记——button_activity
- Linux 性能监测:介绍
- 【算法】乱序检查
- 莫名其妙的电话修改后,变为 2147483647
- 数据传输利器--Event Bus模式
- Python模块学习 ---- threading 多线程控制和处理
- C++细节6
- C++细节6
- IOS第三方之MBProgressHUD
- NSString和NSdata的相互装换
- Java NIO系列教程(六) Selector
- Linux 性能监测:CPU
- (七)SDN 控制器 NOX 源码分析之—— static-deployer
- Spring用@Scheduled 定时任务
- 新锐房地产销售管理系统(部分流程)技术解释(六) 销售管理_客户管理