Codeforces Round #329 (Div. 2) A. 2Char 暴力

A. 2Char

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/593/problem/A

Description

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.


Under two situations the player could score one point.

⋅1. If you touch a buoy before your opponent, you will get one point. For example if your opponent touch the buoy #2 before you after start, he will score one point. So when you touch the buoy #2, you won't get any point. Meanwhile, you cannot touch buoy #3 or any other buoys before touching the buoy #2.

⋅2. Ignoring the buoys and relying on dogfighting to get point. If you and your opponent meet in the same position, you can try to fight with your opponent to score one point. For the proposal of game balance, two players are not allowed to fight before buoy #2 is touched by anybody.

There are three types of players.

Speeder: As a player specializing in high speed movement, he/she tries to avoid dogfighting while attempting to gain points by touching buoys.
Fighter: As a player specializing in dogfighting, he/she always tries to fight with the opponent to score points. Since a fighter is slower than a speeder, it's difficult for him/her to score points by touching buoys when the opponent is a speeder.
All-Rounder: A balanced player between Fighter and Speeder.

There will be a training match between Asuka (All-Rounder) and Shion (Speeder).
Since the match is only a training match, the rules are simplified: the game will end after the buoy #1 is touched by anybody. Shion is a speed lover, and his strategy is very simple: touch buoy #2,#3,#4,#1 along the shortest path.

Asuka is good at dogfighting, so she will always score one point by dogfighting with Shion, and the opponent will be stunned for T seconds after dogfighting. Since Asuka is slower than Shion, she decides to fight with Shion for only one time during the match. It is also assumed that if Asuka and Shion touch the buoy in the same time, the point will be given to Asuka and Asuka could also fight with Shion at the buoy. We assume that in such scenario, the dogfighting must happen after the buoy is touched by Asuka or Shion.

The speed of Asuka is V1 m/s. The speed of Shion is V2 m/s. Is there any possibility for Asuka to win the match (to have higher score)?

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 n lines, 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 Input

4
abb
cacc
aaa
bbb

Sample Output

9

HINT

 

题意

给你一堆单词,然后你只能选包含某两种字母的单词出来

然后问你最多能够选的单词长度总和是多少

题解:

直接暴力枚举两个字母就好了,然后再直接把所有单词都for一遍

代码

 

#include<iostream>
#include<stdio.h>
#include<cstring>
using namespace std;

string s[105];
int main()
{
    int n;scanf("%d",&n);
    for(int i=0;i<n;i++)
        cin>>s[i];
    int ans = 0;
    for(int i=0;i<26;i++)
    {
        for(int j=0;j<26;j++)
        {
            int tmp = 0;
            for(int k=0;k<n;k++)
            {
                int flag = 0;
                for(int p=0;p<s[k].size();p++)
                {
                    if(s[k][p]!=char(i+'a')&&s[k][p]!=char(j+'a'))
                    {
                        flag = 1;
                    }
                }
                if(flag==0)
                    tmp += s[k].size();
            }
            ans = max(ans,tmp);
        }
    }
    cout<<ans<<endl;
}

 

posted @ 2015-11-05 09:50  qscqesze  阅读(322)  评论(0编辑  收藏  举报