zoukankan      html  css  js  c++  java
  • Codeforces Round #307 (Div. 2) B. ZgukistringZ 暴力

    B. ZgukistringZ

    Time Limit: 20 Sec

    Memory Limit: 256 MB

    题目连接

    http://codeforces.com/contest/551/problem/B

    Description

    Professor GukiZ doesn't accept string as they are. He likes to swap some letters in string to obtain a new one.

    GukiZ has strings a, b, and c. He wants to obtain string k by swapping some letters in a, so that k should contain as many non-overlapping substrings equal either to b or c as possible. Substring of string x is a string formed by consecutive segment of characters from x. Two substrings of string x overlap if there is position i in string x occupied by both of them.

    GukiZ was disappointed because none of his students managed to solve the problem. Can you help them and find one of possible strings k?

    Input

    The first line contains string a, the second line contains string b, and the third line contains string c (1 ≤ |a|, |b|, |c| ≤ 105, where |s| denotes the length of string s).

    All three strings consist only of lowercase English letters.

    It is possible that b and c coincide.

    Output

    Find one of possible strings k, as described in the problem statement. If there are multiple possible answers, print any of them.

    Sample Input

    aaa
    a
    b

    Sample Output

    aaa

    HINT

    题意

    给你a,b,c三个串,让你随意交换a串的位置,让b串和c串在a串里面不重复的出现最多次

    题解:

    B题,就老老实实想暴力就好,直接暴力枚举b串出现的次数,然后再算出c串出现的最多次数,然后搞一搞就好了

    蛤蛤

    代码:

    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <vector>
    #include <sstream>
    #include <queue>
    #include <typeinfo>
    #include <fstream>
    #include <map>
    #include <stack>
    typedef long long ll;
    using namespace std;
    //freopen("D.in","r",stdin);
    //freopen("D.out","w",stdout);
    #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
    #define test freopen("test.txt","r",stdin)  
    #define maxn 2000001
    #define mod 10007
    #define eps 1e-9
    const int inf=0x3f3f3f3f;
    const ll infll = 0x3f3f3f3f3f3f3f3fLL;
    inline ll read()
    {
        ll x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    //**************************************************************************************
    
    
    int num[30];
    int tmp[30];
    int num11[30];
    int num22[30];
    int main()
    {
        //test;
        string a,b,c;
        cin>>a>>b>>c;
        for(int i=0;i<a.size();i++)
            num[a[i]-'a']++;
        for(int i=0;i<b.size();i++)
            num11[b[i]-'a']++;
        for(int i=0;i<c.size();i++)
            num22[c[i]-'a']++;
        int flag=1;
        int ans1=0,ans2=0,ans3=0;
        int anss=0;
        for(int i=0;i<=a.size();i++)
        {
            int flag=1;
            for(int j=0;j<30;j++)
                tmp[j]=num[j];
            for(int j=0;j<30;j++)
            {
                if(num11[j]*i>tmp[j])
                    flag=0;
                else
                    tmp[j]-=num11[j]*i;
            }
            if(flag==0)
                anss++;
            if(anss==5)
                break;
            int flag2=inf;
            for(int j=0;j<30;j++)
            {
                if(num22[j]>0)
                    flag2=min(flag2,tmp[j]/num22[j]);
            }
            if(flag2==inf)
                flag2=0;
            if(flag)
                flag2+=i;
            if(ans3<flag2)
            {
                ans1=i;
                ans2=flag2-i;
                ans3=flag2;
            }
        }
        for(int i=0;i<ans1;i++)
            cout<<b;
        for(int i=0;i<ans2;i++)
            cout<<c;
        for(int i=0;i<30;i++)
            num[i]=num[i]-num11[i]*ans1;
        for(int i=0;i<30;i++)
            num[i]=num[i]-num22[i]*ans2;
        for(int i=0;i<30;i++)
        {
            while(num[i]>0)
            {
                num[i]--;
                printf("%c",i+'a');
            }
        }
    }
  • 相关阅读:
    来了!GitHub for mobile 发布!iOS beta 版已来,Android 版即将发布
    五角场之殇。曾与张江、漕河泾、紫竹齐名。如今,上海四大IT科技园是否还在?
    Visual Studio Online 的 FAQ:iPad 支持、自托管环境、Web 版 VS Code、Azure 账号等
    VS Code 1.40 发布!可自行搭建 Web 版 VS Code!
    Visual Studio Online,带来四种开发模式,未来已来。
    基于七牛云对象存储,搭建一个自己专属的极简Web图床应用(手摸手的注释讲解核心部分的实现原理)
    css伪元素::before与::after使用基础示例
    gcc生成静态链接库与动态链接库步骤,并链接生成可执行文件的简单示例
    shell求水仙花数
    shell实现简单的数组排序
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4572908.html
Copyright © 2011-2022 走看看