Advertisement
Riz1Ahmed

From Zero to Infinity

Nov 11th, 2019
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.48 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. struct R{double tot=0,in=0;};
  4. bool vowel(char c){
  5.     return c=='a'||c=='e'||c=='i'||c=='o'||c=='u';
  6. }
  7. bool ForAlice(string s){
  8.     for (int i=0; i<s.size(); i++){
  9.         int vw=0,cn=0;
  10.         vowel(s[i]) ? vw++:cn++;
  11.         for (int j=i+1; j<s.size(); j++){
  12.             vowel(s[j]) ? vw++:cn++;
  13.             if (cn>vw) return false;
  14.         }
  15.     }
  16.     return true;
  17. }
  18. int main(){
  19.     int t,n;
  20.     cin>>t;
  21.     while (cin>>n){
  22.         vector<string> alice,bob;
  23.         string s;
  24.         while (n--){
  25.             cin>>s;
  26.             if (ForAlice(s)) alice.push_back(s);
  27.             else bob.push_back(s);
  28.         }
  29.  
  30.         R cntA[200], cntB[200];
  31.         for (auto it:alice){
  32.             //cout<<it<<" ";puts("");
  33.             int fl[200]={0};
  34.             for (auto jt:it){
  35.                 cntA[jt].tot++;
  36.                 if (!fl[jt]) cntA[jt].in++;
  37.                 fl[jt]=1;
  38.             }
  39.         }
  40.         for (auto it:bob){
  41.             //cout<<it<<" ";puts("");
  42.             int fl[200]={0};
  43.             for (auto jt:it){
  44.                 cntB[jt].tot++;
  45.                 if (!fl[jt]) cntB[jt].in++;
  46.                 fl[jt]=1;
  47.             }
  48.         }
  49.  
  50.         double scoreA=1,scoreB=1,sa=alice.size(),sb=bob.size(),f=1;
  51.         //printf("%f %f\n",sa,sb);
  52.         for (int i='a'; i<='z' && f; i++){
  53.             if (cntA[i].in){
  54.                 scoreA*=cntA[i].in/
  55.                     pow(cntA[i].tot,sa);
  56.                 //printf("Alice=%c=%.0f/%.0f\n",i,cntA[i].in,cntA[i].tot);
  57.             }
  58.  
  59.             if (cntB[i].in){
  60.                 scoreB*=cntB[i].in/
  61.                     pow(cntB[i].tot,sb);
  62.                 //printf("Bob=%c=%.0f/%.0f\n",i,cntB[i].in,cntB[i].tot);
  63.             }
  64.             //if (scoreA>1e7 || scoreB>1e7) f=0;
  65.         }
  66.         double ans=scoreA/scoreB;
  67.         if (ans>1e7) puts("Infinity");
  68.         else printf("%.7f\n",ans);
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement