标签:
1 /*140MS*/ 2 #include<iostream> 3 #include<string> 4 #include<map> 5 #include<algorithm> 6 #include<cstring> 7 #define rep(i, n) for(int i = 0 ; i < n ; i++) 8 using namespace std; 9 string s; map<string, int> vis; 10 int gcd(int a, int b) { 11 if(a < b) swap(a, b); 12 return (b == 0)?a:gcd(b, a % b); 13 } 14 int main() 15 {ios::sync_with_stdio(false); 16 int T; cin >> T; 17 while(T--) { 18 int n; cin >> n; 19 int ans = 0; 20 int toteven = 0; int totodd = 0; vis.clear(); 21 rep(i ,n) { 22 cin >> s; 23 if(s.length() % 2 == 1) { 24 ans += toteven; if(vis.count(s)) ans += vis[s]; 25 if(!vis.count(s)) vis[s] = 0; vis[s]++; 26 totodd++; 27 } 28 else { 29 ans += totodd; if(vis.count(s)) ans += vis[s]; 30 if(!vis.count(s)) vis[s] = 0; vis[s]++; 31 toteven++; 32 } 33 } 34 if(ans == 0) cout << "0/1" << endl; 35 else { 36 int b = (n * (n - 1)) / 2; 37 int t = gcd(ans, b); 38 cout << ans / t << "/" << b / t << endl; 39 } 40 } 41 return 0; 42 }
标签:
原文地址:http://www.cnblogs.com/tooyoungtoosimple/p/4521111.html