Meeting

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=5512

Description

n pagodas were standing erect in Hong Jue Si between the Niushou Mountain and the Yuntai Mountain, labelled from 1 to n. However, only two of them (labelled a and b, where 1≤a≠b≤n) withstood the test of time.

Two monks, Yuwgna and Iaka, decide to make glories great again. They take turns to build pagodas and Yuwgna takes first. For each turn, one can rebuild a new pagodas labelled i (i∉{a,b} and 1≤i≤n) if there exist two pagodas standing erect, labelled j and k respectively, such that i=j+k or i=j−k. Each pagoda can not be rebuilt twice.

This is a game for them. The monk who can not rebuild a new pagoda will lose the game.

Input

The first line contains an integer t (1≤t≤500) which is the number of test cases.
For each test case, the first line provides the positive integer n (2≤n≤20000) and two different integers a and b.

Output

For each test case, output the winner (``Yuwgna" or ``Iaka"). Both of them will make the best possible decision each time.

Sample Input

16
2 1 2
3 1 3
67 1 2
100 1 2
8 6 8
9 6 8
10 6 8
11 6 8
12 6 8
13 6 8
14 6 8
15 6 8
16 6 8
1314 6 8
1994 1 13
1994 7 12

Sample Output

Case #1: Iaka
Case #2: Yuwgna
Case #3: Yuwgna
Case #4: Iaka
Case #5: Iaka
Case #6: Iaka
Case #7: Yuwgna
Case #8: Yuwgna
Case #9: Iaka
Case #10: Iaka
Case #11: Yuwgna
Case #12: Yuwgna
Case #13: Iaka
Case #14: Yuwgna
Case #15: Iaka
Case #16: Iaka

HINT

题意

有n个地点,然后在a,b位置已经修建了佛塔了,每个地点,只能修建一次佛塔

然后有两个人依次修建佛塔

如果要在x位置修建佛塔,那么需要满足存在i,j位置已经修建了佛塔,且x = i + j 或者 x = i - j

谁不能修建,就谁输了

让你输出最后谁能够胜利

题解:

这是一个博弈论,看到a-b的时候,就请想到gcd……

大胆猜一猜结论…… n/gcd(a,b)的奇数和偶数

代码

#include<iostream>
#include<stdio.h>
using namespace std; int gcd(int a,int b)
{
return b==?a:gcd(b,a%b);
}
int main()
{
int t;scanf("%d",&t);
for(int cas=;cas<=t;cas++)
{
int a,b,n;
cin>>n>>a>>b;
int flag = n/gcd(a,b);
if(flag%==)
printf("Case #%d: Iaka\n",cas);
else
printf("Case #%d: Yuwgna\n",cas);
}
}

HDU 5512 Meeting 博弈论的更多相关文章

  1. HDU 5512

    http://acm.hdu.edu.cn/showproblem.php?pid=5512 gcd(a,b)的位置都是可以选的,之后判断一下奇偶 #include <iostream> ...

  2. HDU 5521 Meeting(虚拟节点+最短路)

    Meeting Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total ...

  3. HDU 5521.Meeting 最短路模板题

    Meeting Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total ...

  4. HDU 5512 - Pagodas - [gcd解决博弈]

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5512 Time Limit: 2000/1000 MS (Java/Others) Mem ...

  5. ACM学习历程—HDU 5512 Pagodas(数学)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5512 学习菊苣的博客,只粘链接,不粘题目描述了. 题目大意就是给了初始的集合{a, b},然后取集合里 ...

  6. HDU 5512 Pagodas【博弈】

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5512 题意: 给定集合,最初有两个数a,b,如果两个人依次使用集合中的元素相加减,如果得到的数均不在 ...

  7. hdu 4678 Mine 博弈论

    这是一题简单的博弈论!! 所有的空白+边界的数字(个数为n)为一堆,容易推出其SG函数值为n%2+1: 其他所有的数字(个数为m)的SG值为m%2. 再就是用dfs将空白部分搜一下即可!(注意细节) ...

  8. hdu 4664 Triangulation 博弈论

    看到这题时,当时还不会做,也没搞懂sg函数,于是狠狠的钻研了下博弈论,渐渐的知道了sg函数…… 现在在来做这题就很容易了,1A 打表容易发现在80左右的时候就出现循环节了 代码如下: #include ...

  9. HDU 4312 Meeting point-2(切比雪夫距离转曼哈顿距离)

    http://acm.hdu.edu.cn/showproblem.php?pid=4312 题意:在上一题的基础上,由四个方向改为了八个方向. 思路: 引用自http://blog.csdn.net ...

随机推荐

  1. BasicDataSource配备

    BasicDataSource配置 commons DBCP 配置参数简要说明 前段时间因为项目原因,要在修改数据库连接池到DBCP上,折腾了半天,有一点收获,不敢藏私,特在这里与朋友们共享. 在配置 ...

  2. Hadoop中的InputFormat解析

    1.InputFormat InputFormat是Hadoop平台上Mapreduce输入的规范,仅有两个抽象方法. List<InputSplit> getSplits(), 获取由输 ...

  3. C#网络资源列表

    1, http://club.topsage.com/thread-371996-1-1.html

  4. 获取手机内存\可用内存\单个APP运行内存

    /** 手机总内存 */ private String getTotalMemory() { // 系统内存信息文件 String str1 = "/proc/meminfo"; ...

  5. C++标准库开发心得

    最近放弃MFC,改用C++标准库开发产品.毕竟MFC用熟了,马上改用STL还不太习惯.下面列出下总结的改用STL遇到的问题和解决办法: 1.清除空格 remove_if(iterBegin, iter ...

  6. Launcher2编译

    Android的源码包,压缩文件大概有3个G左右,要使用其中自带的一些源码需要很多技巧,否则会提示找不到一些库,大量的报错让人心神不定,不知所从. 我拿桌面代码举个例子吧. 桌面代码在源码包的pack ...

  7. codeforces 700B Connecting Universities 贪心dfs

    分析:这个题一眼看上去很难,但是正着做不行,我们换个角度:考虑每条边的贡献 因为是一棵树,所以一条边把树分成两个集合,假如左边有x个学校,右边有y个学校 贪心地想,让每条边在学校的路径上最多,所以贡献 ...

  8. Cloudera的安装

    To enable these parts of the tutorial, choose one of the following options: To use Cloudera Express ...

  9. 在ubuntu下安装chrome

    To add PPA in Ubuntu 14.04 / 13.10 / 13.04 / 12.10 / 12.04 First download and install the key from G ...

  10. My implementation of AVL tree

    C++实现的avl平衡树 #include <stdlib.h> #include <time.h> #include <string.h> #include &l ...