您的位置:首页 > 其它

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;

 }

就是这样,,,,,,想不到没做出来。。哎。。。。。。。。


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: