码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 5229 ZCC loving string

时间:2015-05-18 09:18:23      阅读:193      评论:0      收藏:0      [点我收藏+]

标签:博弈论

#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;
}

hdu 5229 ZCC loving string

标签:博弈论

原文地址:http://blog.csdn.net/qq_24667639/article/details/45790529

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!