zoukankan      html  css  js  c++  java
  • Codeforces Round #329 (Div. 2) A.2Char 暴力

    A. 2Char
     

    Andrew often reads articles in his favorite magazine 2Char. The main feature of these articles is that each of them uses at most two distinct letters. Andrew decided to send an article to the magazine, but as he hasn't written any article, he just decided to take a random one from magazine 26Char. However, before sending it to the magazine 2Char, he needs to adapt the text to the format of the journal. To do so, he removes some words from the chosen article, in such a way that the remaining text can be written using no more than two distinct letters.

    Since the payment depends from the number of non-space characters in the article, Andrew wants to keep the words with the maximum total length.

    Input

    The first line of the input contains number n (1 ≤ n ≤ 100) — the number of words in the article chosen by Andrew. Following are nlines, each of them contains one word. All the words consist only of small English letters and their total length doesn't exceed 1000. The words are not guaranteed to be distinct, in this case you are allowed to use a word in the article as many times as it appears in the input.

    Output

    Print a single integer — the maximum possible total length of words in Andrew's article.

    Sample test(s)
    input
    4
    abb
    cacc
    aaa
    bbb
    output
    9
     
    Note

    In the first sample the optimal way to choose words is {'abb', 'aaa', 'bbb'}.

    In the second sample the word 'cdecdecdecdecdecde' consists of three distinct letters, and thus cannot be used in the article. The optimal answer is {'a', 'a', 'aaaa'}.

    题意:给你n个字符串只含小写字母,现在挑出任意个串,个数最大,但是所挑的串只含两种字母

    题解:预处理出每个串的字母种类

          在暴力枚举两种串就好了

    ///1085422276
    #include<bits/stdc++.h>
    using namespace std ;
    typedef long long ll;
    #define mem(a) memset(a,0,sizeof(a))
    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;
    }
    //****************************************
    #define maxn 1000000+5
    #define mod 1000000007
    vector<int >G[500];
    int H[200];
    int aa[500],n;
    char a[101][1001];
    int main(){
       mem(H);
       scanf("%d",&n);
        for(int i=1;i<=n;i++){
            scanf("%s",a[i]);
            int flag=0;
            for(int j=0;j<strlen(a[i]);j++){
                H[a[i][j]]++;
                flag++;G[i].push_back(a[i][j]);
            }
            aa[i]=flag;
        }
        int sum;
        int ans=0;
         for(int i='a';i<='z';i++){
            for(int j='a';j<='z';j++){
                if(i==j)continue;
                sum=0;
                for(int k=1;k<=n;k++){
                            bool can=1;
                         for(int g=0;g<G[k].size();g++){
                            if(G[k][g]!=i&&G[k][g]!=j)can=0;
                         }
                    if(can)sum+=strlen(a[k]);
                }
                ans=max(sum,ans);
            }
        }cout<<ans<<endl;
      return 0;
    }
    代码
  • 相关阅读:
    CentOS下Zabbix安装部署及汉化
    用jmeter通过ssl验证访问https
    VMware安装CentOS时,无法以图形界面安装解决办法
    MySQL数据库不能远程访问的解决办法
    CentOS搭建LNMP环境
    jstack+top定位性能问题
    用Fiddler模拟低速网络环境
    Linux下history命令用法
    Jmeter3.0发布,版本更新都更新了什么
    【转】gc日志分析工具
  • 原文地址:https://www.cnblogs.com/zxhl/p/4939090.html
Copyright © 2011-2022 走看看