hdu 5229 ZCC loving string

本文探讨了使用C++编程语言解决复杂编程问题的方法,包括利用头文件、输入输出流、数学运算库等实现高效代码。通过实例展示了如何通过算法优化、数据结构设计和错误处理来提升程序性能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdlib>
#include <cmath>
#include <set>
#include <map>
#include <vector>
#include <cstring>

#define INF 100000000
using namespace std;
long long int gcd(long long a,long long b){
    return b == 0?a:gcd(b,a%b);
}
int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        long long int n;
        cin >> n;
        map<string,int> a;
        
        int odd = 0;
        
        for(int i = 0;i < n;i++){
            string b;
            cin >> b;
            odd += b.length()%2;    
            if(a.find(b)!=a.end()){
                a[b]++;
            }
            else{
                a[b] = 1;
            }
        }
        long long int ans = 0;
        for(map<string,int>::iterator ite = a.begin();ite != a.end();ite++){
            long long int t = ite->second;
            ans += t*(t-1)/2;
        }
        ans += odd*(n-odd);
//        cout << ans << endl;
        long long  tmp = n * (n-1)/2;
        
        long long int gc = gcd(tmp,ans);
        cout << ans/gc << "/" << tmp/gc << endl;
//        printf("%d/%d\n",ans/gc,tmp/gc);
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值