• --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);
         }
        
        
    }
  • 相关阅读:
    unix操作系统一些笔记
    安装SQL SERVER2008 R2出现的几个问题
    js中的类型和函数参数传递类型问题
    js一些要点
    百度2015年前端笔试题(南京区域)
    js 函数中的 this 问题
    html细节
    前后台读取Web.config中的值的方法
    使用的 SQL Server 版本不支持数据类型“datetime2”.
    物料主数据MRP4中的独立/集中
  • 原文地址:https://www.cnblogs.com/lovelystone/p/4509465.html
Copyright © 2020-2023  润新知