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 概率题。(母函数
原文地址:http://blog.csdn.net/qq574857122/article/details/27852241