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 * @ ...
随机推荐
- 【高级算法】遗传算法解决3SAT问题(C++实现)
转载请注明出处:http://blog.csdn.net/zhoubin1992/article/details/46910079 1 SAT问题描写叙述 命题逻辑中合取范式 (CNF) 的可满足性问 ...
- office系列调节背景主题
更改背景主题可以参考:https://jingyan.baidu.com/article/ff42efa9332adec19e220200.html 但是这种方法只是改变了整个软件外框架的背景颜色.以 ...
- mybatis generator配置,Mybatis自动生成文件配置,Mybatis自动生成实体Bean配置
mybatis generator配置,Mybatis自动生成文件配置,Mybatis自动生成实体Bean配置 ============================== 蕃薯耀 2018年3月14 ...
- Linux Redis安装,Linux如何安装Redis,Linux Redis自动启动,Redis开机启动
Linux Redis安装,Linux如何安装Redis,Linux Redis自动启动,Redis开机启动 >>>>>>>>>>>& ...
- 使用HTML5监测网站性能
在这个信息爆炸的互联网时代,越来越多的人缺少了等待的耐心,网站性能对于一个网站来说越来越重要.以下为监控到的网站打开时间对跳出率的影响: 当网站打开时间在0-1秒时,跳出率为12% 当网站打开时间在1 ...
- 消息中间件activemq-5.14.1安全验证配置
activemq分为控制端和客户端,下面分别介绍安全认证配置方法. 1.控制端安全配置 (1). ActiveMQ目录conf下找到jetty.xml: <bean id="secur ...
- 【权限维持】window几种隐藏技术
“真正”隐藏文件 使用Attrib +s +a +h +r命令就是把原本的文件夹增加了系统文件属性.存档文件属性.只读文件属性和隐藏文件属性. attrib +s +a +h +r c:\test 这 ...
- linux 开机自启
cd /home/dpf 1.vi startup.sh #!/bin/shecho "hello world" >> /home/dpf/test.txt vi mq ...
- 初步总结javascript中学习DOM之前的知识
嘿嘿,又到了周末时间,周六其实就是总结这周的学习的,记得周二周三刚开始接触javascript时间,还是不知道怎么学习的,就感觉找不到方向,那时间学习的只是总结了一些简单的定义或者是学习结构,今天就把 ...
- CSS-禁用a标签
<style> a.disabled { pointer-events: none; filter: alpha(opacity=50); /*IE滤镜,透明度50%*/ -moz-opa ...