随笔—邀请赛前练— Codeforces Round #329 (Div. 2) 2Char

题意:给你多个字符串,只保留2及2个以内的字符,丢弃多余的字符串,问你最后留下的字符串最长能有多长?

思路:

1、 对每个字符串处理出  process[fir][sec]  只包含fir字符和sec字符 当前的最大长度。当然,超过2个字符的字符串自动跳过。

2、 注意合并 process[fir][sec]、process[sec][fir]、process[fir][0]、process[sec][0]

3、 合并的过程还要注意特殊情况 process[fir][0] + process[sec][0]   .注意去除fir==sec的情况。

#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<iostream>
#include<map>
using namespace std;

#define  MAX(x,y) (((x)>(y)) ? (x) : (y))
#define  MIN(x,y) (((x) < (y)) ? (x) : (y))
#define ABS(x) ((x)>0?(x):-(x))

int pos[3];
int process[30][30];
int vis[30];

int main()
{
    char str[1010];
    int n;
    cin>>n;
    while(n--){
        int cnt=0;
        memset(pos,0,sizeof(pos));
        memset(vis,0,sizeof(vis));
        cin>>str;
        int len=strlen(str);
        for(int i=0; i<len; i++){
            int num=str[i]-‘a‘+1;
            if( !vis[num] ){
                vis[num]=1;
                pos[cnt++]=num;
            }
            if(cnt == 3)
                break;
        }
        if(cnt != 3){
            int fir = pos[0];
            int sec = pos[1];
            process[fir][sec] += len;
        }
    }

    int mmax=0;
    for(int i=1; i<=26; i++){
        for(int j=0; j<26; j++){
            int sum=0;
            if(j!=0 && process[i][j]){
                sum += process[i][j] + process[j][i] + process[i][0] + process[j][0];
            }
            if(j==0){
                for(int k=1; k<=26; k++){
                    if(k == i)
                        continue;
                    sum=0;
                    sum += process[i][0] + process[k][0];
                    mmax=MAX(sum,mmax);
                }
            }
            mmax=MAX(sum,mmax);
        }
    }
    cout<<mmax<<endl;
    return 0;
}
时间: 2024-10-15 05:39:01

随笔—邀请赛前练— Codeforces Round #329 (Div. 2) 2Char的相关文章

随笔—邀请赛前训—Codeforces Round #327 (Div. 2) Rebranding

题意:一个字符串,做n次变换,每次变换是把a字符与b字符全部调换.求全部调换完成后的字符串. 这道题目我一开始理解错意思了,理解成将所有a字符变成b字符,我觉得这样出貌似还更有挑战性一点..口亨 #include<cstdio> #include<cstring> #include<map> #include<iostream> using namespace std; #define MAX(x,y) (((x)>(y)) ? (x) : (y))

随笔—邀请赛前训—Codeforces Round #328 (Div. 2) A. PawnChess

题意:给你一个8×8的棋盘分布,红黑棋子,双方只能朝上下其中一个方向移动,不可跨越对方或自己的棋子,最先到对面底部的人赢.问谁赢? 思路:上下2排同时开始扫,先扫到谁都棋,谁就赢(前提是没有对方的人挡路..) #include<cstdio> #include<cstring> #include<iostream> using namespace std; #define MAX(x,y) (((x)>(y)) ? (x) : (y)) #define MIN(x

随笔—邀请赛前训— Codeforces Round #330 (Div. 2) Vitaly and Night

题意:给你很多对数,要么是0要么是1.不全0则ans++. 思路即题意. #include<cstdio> #include<cstring> #include<iostream> using namespace std; #define MAX(x,y) (((x)>(y)) ? (x) : (y)) #define MIN(x,y) (((x) < (y)) ? (x) : (y)) #define ABS(x) ((x)>0?(x):-(x))

随笔—邀请赛前训— Codeforces Round #330 (Div. 2) B题

题意: 这道英文题的题意稍稍有点复杂. 找长度为n的数字序列有多少种.这个序列可以分为n/k段,每段k个数字.k个数可以变成一个十进制的数Xi.要求对这每n/k个数,剔除Xi可被ai整除的情况,剔除X的第一个数(包括前导0)是bi的情况.问剩下的组合有多少种. 思路: 这题我是一波三折的.首先也没有考虑很多,看着可以暴力模拟过程,我就直接开始敲了,几个for循环敲出来,再把bug调一调和特殊情况考虑考虑,交了之后开始TLE,这时候意识到复杂度太大了,于是开始优化,做了(b[i])*(mmax/1

随笔—邀请赛前练—CodeForces 588B

题意:给一个数,求最大的一个因子,这个因子还要满足不能有平方数是他的因子. 我的解法几乎是暴力的,应该可以用数学的方法不暴力(或者说不那么“暴力”)求出来. 我的解法是: #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #include<cmath> #include<set> using namespace std; #define

Codeforces Round #329 (Div. 2)B. Anton and Lines 贪心

B. Anton and Lines The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Codeforces. In the task he was given a set of n lines defined by the equations y = ki·x + bi. It was necessar

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, h

Codeforces Round #279 (Div. 2) ABCD

Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard input/

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i