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;
}

最新文章

  1. Oracle-BPM安装详解
  2. spring源码:核心组件(li)
  3. Schwarz积分公式
  4. js 获取样式兼容方法
  5. Dapper.NET 使用简单举例
  6. centos修改文件及文件夹权限
  7. 在阿里云linux下使用SVN访问VisualSVN出错:SSL handshake failed: SSL error: Key usage violation in certificate has been detected
  8. Android Animation 动画属性
  9. [转] PostgreSQL学习手册(数据表)
  10. 自定义JsonResult处理JSON序列化DateTime类型数据(Ext4.2+ASP.NET MVC 4)
  11. bad interpreter:No such file or directory 解决方法
  12. DOS界面下的翻译软件制作
  13. Qt中事件分发源代码剖析
  14. LINK1104:无法打开文件&quot;\.obj&quot;原因及解决办法
  15. JSP总结(一)——基础(汇总)
  16. mysql监测工具
  17. c#递归实现螺旋数组
  18. React-Native项目中使用Redux
  19. hdu 5446(2015长春网络赛J题 Lucas定理+中国剩余定理)
  20. 全局变量的使用【C++/Qt】

热门文章

  1. PHP使用纯真IP数据库
  2. Python之路Day10
  3. hackyviewpager有什么用
  4. SolrCloud Hello Word
  5. 一个load飙高的过程分析,非常有价值(转)
  6. OGG同构(ORACLE-ORACLE)、异构(ORACLE-MYSQL)同步配置及错误解析
  7. Sereja and Bottles
  8. BZOJ 2599 [IOI2011]Race【Tree,点分治】
  9. assert()用法
  10. 自定义的Server