标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/131072 K (Java/Others)
Total Submission(s): 264 Accepted Submission(s): 100
(去重 + 奇数 * 偶数)/( n*(n-1) ),不过得约分(GCD);
去重就是重复的排列(假设重复的是x ,x = ( x*(x-1)) );
奇数 + 偶数 = 奇数
#include<stdio.h> #include<map> #include<string> #include<iostream> #include<string.h> using namespace std; __int64 gcd(__int64 a,__int64 b){ if(b)return gcd(b,a%b); else return a; } int main(){ int t; scanf("%d",&t); while(t--){ __int64 ans = 0; __int64 ji,ou; ji = ou = 0; map<string,int>m; __int64 n; char a[200010]; scanf("%I64d",&n); for(int i = 0;i<n;i++){ scanf("%s",a); m[a] ++; int len = strlen(a); if(len % 2)ji++; else ou++; } map<string,int>::iterator itor; for(itor = m.begin();itor!=m.end();itor++){ __int64 x = itor->second; if(x > 1)ans += x * (x-1)/2; //printf("%d\n",x); } __int64 zi,mus; zi = ans + ji*ou; mus = (n*(n-1))/2; __int64 gg = gcd(zi,mus); printf("%I64d",zi/gg); printf("/"); printf("%I64d\n",mus/gg); } }
标签:
原文地址:http://www.cnblogs.com/lovelystone/p/4509465.html