CodeForces - 551B ZgukistringZ(暴力)

41 篇文章 0 订阅
32 篇文章 0 订阅

真的很弱智,我tmT了一年,找不出问题在哪里,才发现我每个字符串的for循环都是到strlen(),唉,用cin>>string,习惯了,string真的好蠢.

/*  xzppp  */
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <list>
#include <math.h>
#include <iomanip>
using namespace std;
#define FFF freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define mp make_pair
typedef long long  LL;
typedef unsigned long long ULL;
const int MAXN = 100000;
const int  INF = 0x7fffffff;
const int MOD = 1e9+7;
char a[MAXN+17],b[MAXN+17],c[MAXN+17];
int bn[26+17],cn[26+17],ah[26+17];
int check(int h[26+17],int n[26+17])
{
    int res = INF,have[26+17],need[26+17];
    for (int i = 0; i < 26; ++i)
    {
        have[i] = h[i];
        need[i] = n[i];
    }
    for (int i = 0; i < 26; ++i)
    {
        if(need[i])
        {
            int temp = have[i]/need[i];
            res = min(res,temp);
        }
    }
    return  res;
}
int main()
{
    //FFF
    scanf("%s%s%s",a,b,c);
    for (int i = 0; a[i]!='\0'; ++i)
        ah[a[i]-'a']++;
    for (int i = 0; b[i]!='\0'; ++i)
        bn[b[i]-'a']++;
    for (int i = 0; c[i]!='\0'; ++i)
        cn[c[i]-'a']++;
    int bh = check(ah,bn);
    int ans = 0,x=0,y=0;
    int ori[26+17];
    for (int i = 0; i < 26; ++i)
        ori[i] = ah[i];
    for (int i = 0; i <= bh; ++i)
    {
        for (int i = 0; i < 26; ++i)
            ah[i] = ori[i];
        for(int k =0 ;k<26;++k)
            ah[k] -= i*bn[k];           
        int temp = check(ah,cn);
        if(i+temp>ans)
        {
            ans = i+temp;
            x = i;
            y = temp;
        }
    }
    for (int i = 0; i < x; ++i)
        printf("%s",b);
    for (int i = 0; i < y; ++i)
        printf("%s",c);
    for (int i = 0; i < 26; ++i)
        ori[i]-=(x*bn[i]+y*cn[i]);
    for (int i = 0; i < 26; ++i)
        while(ori[i]--) printf("%c",i+'a');
    cout<<endl;
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值