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 _(:зゝ∠)_的更多相关文章

  1. HDU 4937 Lucky Number 规律题_(:зゝ∠)_

    把全部合法的进制打出来会发现合法的进制都是在 n/3 n/4 n/5的边上 然后暴力边上的进制数.. #include <cstdio> #include <set> type ...

  2. HDU 4876 ZCC loves cards _(:зゝ∠)_ 随机输出保平安

    GG,,,g艹 #include <cstdio> #include <iostream> #include <algorithm> #include <st ...

  3. HDU 4915 Parenthese sequence _(:зゝ∠)_ 哈哈

    哦,我没做 #include <cstdio> #include <cstring> #include <algorithm> const int N = 1000 ...

  4. UVALive 6663 Count the Regions 离散+bfs染色_(:зゝ∠)_

    题目链接:option=com_onlinejudge&Itemid=8&page=show_problem&problem=4675">点击打开链接 gg.. ...

  5. Oracle学习总结_day03_day04_条件查询_排序_函数_子查询

    本文为博主辛苦总结,希望自己以后返回来看的时候理解更深刻,也希望可以起到帮助初学者的作用. 转载请注明 出自 : luogg的博客园 谢谢配合! day03_条件查询_排序_函数 清空回收站: PUR ...

  6. C Primer Plus_第6章_循环_编程练习

    1.题略 #include int main(void) { int i; char ch[26]; for (i = 97; i <= (97+25); i++) { ch[i-97] = i ...

  7. 转:HIBERNATE一些_方法_@注解_代码示例---写的非常好

    HIBERNATE一些_方法_@注解_代码示例操作数据库7步骤 : 1 创建一个SessionFactory对象 2 创建Session对象 3 开启事务Transaction : hibernate ...

  8. 迅为4412开发板Linux驱动教程——总线_设备_驱动注册流程详解

    本文转自:http://www.topeetboard.com 视频下载地址: 驱动注册:http://pan.baidu.com/s/1i34HcDB 设备注册:http://pan.baidu.c ...

  9. 3.IP地址分类_规划_子网掩码

    IP地址分类_规划_子网掩码 3.1MAC地址 网卡的身份证号———MAC地址 MAC地址的长度为48位(6个字节),通常表示为12个16进制数,每2个16进制数之间用冒号隔开,如:08:00:20: ...

随机推荐

  1. String类的一些方法

    String 类有以下方法: startsWith(String prefix) boolean java.lang.String.startsWith(String prefix) Tests if ...

  2. C语言深度剖析---预处理(define)(转载)

    1.数值宏常量     #define宏定义是个演技非常高超的替身演员,但也会耍大牌的,所以我们使用它要慎之又慎.它可以出现在代码的任何地方,从本行宏定义开始,以后的代码都认识宏了:也可以把任何东西都 ...

  3. django-model-utils

    一个普通例子: todos = Todo.objects.filter(owner=request.user).filter(is_done=False).filter(priority=1) 弊端: ...

  4. docker学习笔记16:Dockerfile 指令 ADD 和 COPY介绍

    一.ADD指令 ADD指令的功能是将主机构建环境(上下文)目录中的文件和目录.以及一个URL标记的文件 拷贝到镜像中. 其格式是: ADD  源路径  目标路径 如: #test FROM ubunt ...

  5. oschina开源硬件其它开源,开源硬件

    硬件驱动/工具 25Linux内核 101桌面环境 40开源字体 58嵌入式操作系统 33输入法 110开源硬件 57开源图书 5开源家居 17物联网 87开源货币/比特币 32NASA 开源项目 1 ...

  6. BZOJ 4145: [AMPPZ2014]The Prices( 状压dp + 01背包 )

    我自己只能想出O( n*3^m )的做法....肯定会T O( nm*2^m )做法: dp( x, s ) 表示考虑了前 x 个商店, 已买的东西的集合为s. 考虑转移 : 先假设我们到第x个商店去 ...

  7. python读取文件内容方法

    1) readline 每次读一行,返回序列 2) readlines 一次全部读出,返回序列 3) numpy 的genfromtxt,返回为np的矩阵格式 import numpy as np f ...

  8. Solr基础理论与维护管理快速上手(含查询参数说明)

    1. solr基础 因为 Solr 包装并扩展了 Lucene,所以它们使用很多相同的术语.更重要的是,Solr 创建的索引与 Lucene 搜索引擎库完全兼容.通过对 Solr 进行适当的配置,某些 ...

  9. keepalived 结合mysql 自动切换

    启动keepalived:/usr/local/sbin/keepalived -D -d -S 0 master ip:192.168.32.6 master:/root/sbin# cat /et ...

  10. 只启动一个zookeeper配置 server1只需要配置一个

    [root@wx03 conf]# cat zoo.cfg # The number of milliseconds of each tick tickTime=2000 # The number o ...