zoukankan      html  css  js  c++  java
  • --BestCoder (#41-B)

    ZCC loves strings

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/131072 K (Java/Others)
    Total Submission(s): 264    Accepted Submission(s): 100


    Problem Description
    ZCC has got N strings. He is now playing a game with Miss G.. ZCC will pick up two strings among those N strings randomly(A string can't be chosen twice). Each string has the same probability to be chosen. Then ZCC and Miss G. play in turns. Miss G. always plays first. In each turn, the player can choose operation A or B.
      
    Operation A: choose a non-empty string between two strings, and delete a single letter at the end of the string.
        
    Operation B: When two strings are the same and not empty, empty both two strings.
      
    The player who can't choose a valid operation loses the game.
      
    ZCC wants to know what the probability of losing the game(i.e. Miss G. wins the game) is.
     
    Input
    The first line contains an integer T(T5) which denotes the number of test cases.
      
    For each test case, there is an integer N(2N20000) in the first line. In the next N lines, there is a single string which only contains lowercase letters. It's guaranteed that the total length of strings will not exceed 200000.
     
    Output
    For each test case, output an irreducible fraction "p/q" which is the answer. If the answer equals to 1, output "1/1" while output "0/1" when the answer is 0.
     
    Sample Input
    1 3 xllendone xllendthree xllendfour
     
    Sample Output
    2/3

    (去重 + 奇数 * 偶数)/( 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
    ",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
    ",mus/gg);
         }
        
        
    }
  • 相关阅读:
    将数组格式的字符串转换成数组
    引号嵌套引起的问题
    如何使用for循环把对象push到数组中,且前面的值不会被覆盖
    如何把一个大的对象,转成若干个小对象,然后在放到数组中
    前端如何设置一天只能点击一次的以及如何去判断第二天0点刷新的一些问题
    let和const的理解以及let,const,var的区别
    watch监控和computed监控
    媒体查询
    react中redux+react-redux插件的应用
    react中控制div的位置移动动画
  • 原文地址:https://www.cnblogs.com/lovelystone/p/4509465.html
Copyright © 2011-2022 走看看