码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 4839 The Game of Coins 概率题。(母函数

时间:2014-06-01 13:58:31      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:c   class   blog   code   a   tar   

The Game of Coins


mark:

#include"cstdio"  
#include"iostream"  
#include"queue"  
#include"algorithm"  
#include"set"  
#include"queue"  
#include"cmath"  
#include"string.h"  
#include"vector"
using namespace std; 

#define ll __int64
inline ll abs(ll x){return x>0?x:-x;}
ll gcd(ll a,ll b){if(a>b)swap(a,b);    while(a){    b%=a;swap(a,b);    }return b;}

int main() {
    ll T, i, j;scanf("%I64d", &T);
    for(ll t = 1; t <= T; t++){
        char a[1005], b[1005];
        scanf("%s %s", a, b);
        printf("Case #%I64d:\n", t);
        ll len = strlen(a);
        ll ga = 0, fa = 0, gb = 0, fb = 0;
        for (i = 1; i<=len; i++) 
        {
            if (strncmp(a, a+len-i, i) == 0) ga |= (ll)1 << i;
            if (strncmp(a, b+len-i, i) == 0) fa |= (ll)1 << i;
            if (strncmp(b, a+len-i, i) == 0) gb |= (ll)1 << i;
            if (strncmp(b, b+len-i, i) == 0) fb |= (ll)1 << i;
        }
        ll dou1 = abs(ga - gb);
        ll dou2 = abs(fb - fa);
        
        if (dou1 == dou2) { puts("1/2"); continue; }
        if (dou1 == 0) { puts("1"); continue; }
        if (dou2 == 0) { puts("0"); continue; }
        ll GCD = gcd(dou1, dou2);
        dou1 /= GCD;    dou2 /= GCD;
        printf("%I64d/%I64d\n", dou2, dou1+dou2);
    }
    return 0;
}


HDU 4839 The Game of Coins 概率题。(母函数,布布扣,bubuko.com

HDU 4839 The Game of Coins 概率题。(母函数

标签:c   class   blog   code   a   tar   

原文地址:http://blog.csdn.net/qq574857122/article/details/27852241

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!