Codeforces Round 734 (Div. 3) C. Interesting Story

https://codeforces.com/problemset/problem/1551/C

在这里插入图片描述

 

题目大意:

        从一堆单词(只含a,b,c,d,e)中进行挑选,保证单个字母出现的最大次数严格大于其余字母的出现次数,求最多能选几个单词

解题思路:

        第一次写题解居然挑了个这么简单的题不愧是我

        已知字符串只含五个字母,则可以直接枚举,得到最大值

        每个单词的贡献就是单个字母出现的最大次数减去其余字母的出现次数,则可以直接将5个字母所有的每个单词贡献值进行排序,一直相加直到和小于等于0,然后求得以其字母为主的最大单词数,逐一比较出最大值

#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
const ll Mod = 1e9 + 7;
const ll mod9 = 998244353;
const ll Max = 1e6 + 7;
const ll MAX = 1e3 + 100;
const ll N = 3e5+10;
const ll inf = 1e15+100;
const double pi=acos(-1.0);
const double eps=1e-8;
//char buf[1<<20],*p1,*p2;
#define nl "\n"
#define fir first
#define sec second
//#define re register
//#define int ll
//#define gc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf,1,1<<20,stdin), p1 == p2) ? 0 : *p1++)
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pii pair<int,int>
#define pll pair<long long,long long>
#pragma comment (linker,"/STACK:102400000,102400000")
using namespace std;

ll arr[150][150],f[150][150],vis[N],date[N],cntn[210];
ll suma[Max],sumb[Max],sumn[N];
char chs[27];
string s;;
int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};
vector<int>e[N];
ll n,m;
vector<int>vn;

bool cmp(pii a,pii b){
    int dis1=a.first-a.second,dis2=b.first-b.second;//最大次数与其余次数之差
    if(dis1==dis2){
        if(a.first==b.first)
            return a.second<b.second;
        return a.first>b.first;
    }
    return dis1>dis2;
}

int main() {
    ios;
    //cout << fixed;
    //cout.precision(18);
    //cout.flush();
    int i, j;
    ll  T,k,u,v,g,h,t,t1,t2,p,q,op,mx,mn,x,y,z,l,r,len,mid,pos,cnt,last,sumn,other;
    string str,s1,s2,s3,te1,te2,sf,sk;
    char ch,ch1,ch2;
    bool flag,f1,f2,f3,cle;
    suma[0]=0;sumb[0]=0;
    T=1;
    cin>>T;
    while(T--) {
        cin>>n;
        mx=0;
        vector<pii>ve[5];
        while(n--){
            cin>>s;
            l=s.size();
            vector<int>vc(5);
            for(i=0;i<s.size();i++)
                vc[s[i]-'a']++;
            for(i=0;i<5;i++)
                ve[i].push_back({vc[i],l-vc[i]});
        }
        for(i=0;i<5;i++)
            sort(ve[i].begin(),ve[i].end(),cmp);
        /*for(i=0;i<5;i++){
            for(auto [x,y]:ve[i])
                cout<<x<<" "<<y<<"      ";
            cout<<nl;
        }*/
        for(i=0;i<5;i++){
            sumn=0;cnt=0;
            for(j=0;j<ve[i].size();j++){
                sumn+=ve[i][j].first-ve[i][j].second;
                if(sumn>0)
                    cnt++;
                else
                    break;
            }
            mx=max(mx,cnt);
        }
        cout<<mx<<nl;
    }

    //system("pause");
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值