HDU 5512 - Pagodas - [gcd解决博弈]
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5512
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Problem 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.
#include<cstdio>
int gcd(int m,int n){return n?gcd(n,m%n):m;}
int n,a,b;
int main()
{
int t;
scanf("%d",&t);
for(int kase=;kase<=t;kase++)
{
scanf("%d%d%d",&n,&a,&b);
int cnt=,d=gcd(a,b);
for(int i=gcd(a,b);i<=n;i+=d) cnt++;
printf("Case #%d: %s\n",kase,(cnt%)?"Yuwgna":"Iaka");
}
}
HDU 5512 - Pagodas - [gcd解决博弈]的更多相关文章
- HDU 5512 Pagodas (gcd)
题目:传送门. 题意:t组数据,每组数据给定n,a,b,a!=b,在[1,n]的这些点中,每次选取a+b或a-b或b-a点,选取过的点在下次选取的时候可以当做ab来用继续选取,谁不能继续选取谁就输,问 ...
- HDU 5512 Pagodas【博弈】
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5512 题意: 给定集合,最初有两个数a,b,如果两个人依次使用集合中的元素相加减,如果得到的数均不在 ...
- HDU 5512 Pagodas (2015沈阳现场赛,找规律+gcd)
Pagodas Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Sub ...
- hdu 5512 Pagodas 扩展欧几里得推导+GCD
题目链接 题意:开始有a,b两点,之后可以按照a-b,a+b的方法生成[1,n]中没有的点,Yuwgna 为先手, Iaka后手.最后不能再生成点的一方输: (1 <= n <= 2000 ...
- ACM学习历程—HDU 5512 Pagodas(数学)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5512 学习菊苣的博客,只粘链接,不粘题目描述了. 题目大意就是给了初始的集合{a, b},然后取集合里 ...
- HDU 5512 Pagodas
2015 ACM / ICPC 沈阳现场赛 D 题 找了一小时规律......发现是个GCD. #include<cstdio> #include<cstring> #incl ...
- HDU 5512 Pagodas (数论)
题意:给了初始的集合{a, b},然后取集合里的两个元素进行加或者减的操作,生成新的元素.问最后最多能生成多少个元素.问答案的奇偶性. 析:多先写几个你就会发现,答案就是 n / gcd(a, b). ...
- 从SG函数浅谈解决博弈问题的通法
基于笔者之前对于几种二元零和博弈游戏的介绍,这里将其思想进行简单的提炼,并引出解决这类二元零和博弈游戏的强大工具——SG函数. 其实对于博弈游戏如Bash.Nim等基本类型,异或一些比较高级的棋类游戏 ...
- HDU 1524 树上无环博弈 暴力SG
一个拓扑结构的图,给定n个棋的位置,每次可以沿边走,不能操作者输. 已经给出了拓扑图了,对于每个棋子找一遍SG最后SG和就行了. /** @Date : 2017-10-13 20:08:45 * @ ...
随机推荐
- C#中AppDomain.CurrentDomain.BaseDirectory与Application.StartupPath的区别
// 获取程序的基目录. System.AppDomain.CurrentDomain.BaseDirectory // 获取模块的完整路径. System.Diagnostics.Process.G ...
- 为什么调用 FragmentPagerAdapter.notifyDataSetChanged() 并不能更新其 Fragment?【转载】
转载自:http://www.cnblogs.com/dancefire/archive/2013/01/02/why-notifyDataSetChanged-does-not-work.html ...
- Linux命令缩写的全称
[目录|文件] ls : list(列出目录内容) pwd : print work directory(打印当前目录,现示当前工作目录的绝对路径) cd : change directory(改变目 ...
- association 的使用
<resultMap id="wmsTaskMap" type="WmsTask"> <id column="ID" jd ...
- phonegap入门–1 Android 开发环境搭建
一.JDK 安装JDK,安装包中包含了JDK和JRE两部分,建议将它们安装在同一个盘符下面. 配置环境变量: 1.右键点击我的电脑,选择属性,点击高级选项卡,选择环境变量. 2.找到Path变量名(无 ...
- Selenium 基本用法
如下,使用 Selenium 打开淘宝首页并获取页面源代码: from selenium import webdriver browser = webdriver.Chrome() # 声明一个浏览器 ...
- 一个汉字转拼音的php类
代码来自网上,可用 <?php function Pinyin($_String, $_Code='gb2312') { $_DataKey = "a|ai|an|ang|ao|ba| ...
- 【cs229-Lecture3】为什么要选择“最小二乘法”这个指标
视频地址:http://v.163.com/movie/2008/1/E/B/M6SGF6VB4_M6SGHM4EB.html 具体的推导过程,讲义上都有,已经很详细了.这里的推导过程大都是自己为了练 ...
- Java 8 特性 – 终极手册
简介 毫无疑问,Java 8的发布是自Java 5(它的发布已远在2004年)以来在Java世界中最重大的事情.它带来了超多的新特性,这些特性分别被加入到Java语言本身.Java编译器.类库.工具类 ...
- 【大数据系列】安装Ambari
一.Ambari简介 The Apache Ambari project is aimed at making Hadoop management simpler by developing soft ...