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 __int64inline 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 _ (: Зゝ∠) _