hdu 5229 ZCC loving string

来源:互联网 发布:php配置环境工具 编辑:程序博客网 时间:2024/05/08 09:44
#include <cstdio>#include <iostream>#include <algorithm>#include <queue>#include <stack>#include <cstdlib>#include <cmath>#include <set>#include <map>#include <vector>#include <cstring>#define INF 100000000using 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;}

0 0
原创粉丝点击