Pagodas

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 70    Accepted Submission(s): 62

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.
 
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
 
Source

【题意】:

选已存在的i j来建新塔(i+j or i-j)

【解题思路】:

沈阳最水的题,仍然挂了2发。。。

一开始以为除了a b均是偶数的情况均能出现所有数(被样例带歪了)

多写几个例子就发现可能出现的数字是gcd(a,b)的倍数,答案即为判断 n/gcd(a,b)-2 奇偶~

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<cmath>
  5. #include<algorithm>
  6. #define eps 1e-8
  7. #define zero(x)(((x)>0?(x):-(x))<eps)
  8. #define PI acos(-1.0)
  9. #define LL long long
  10. #define maxn 100100
  11. #define IN freopen("in.txt","r",stdin);
  12. using namespace std;
  13.  
  14. int gcd(int a,int b)
  15. {
  16. return !b? a:gcd(b,a%b);
  17. }
  18.  
  19. int main(int argc, char const *argv[])
  20. {
  21. //IN;
  22.  
  23. int t,ca=;scanf("%d",&t);
  24. while(t--)
  25. {
  26. int n,a,b;
  27. scanf("%d %d %d",&n,&a,&b);
  28.  
  29. int cnt = n/gcd(a,b) - ;
  30.  
  31. if(cnt%==) printf("Case #%d: Iaka\n",ca++);
  32. else printf("Case #%d: Yuwgna\n", ca++);
  33. }
  34.  
  35. return ;
  36. }

HDU 5512 Pagodas (2015沈阳现场赛,找规律+gcd)的更多相关文章

  1. HDU 5510 Bazinga (2015沈阳现场赛,子串判断)

    Bazinga Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Sub ...

  2. hdu 4731 2013成都赛区网络赛 找规律

    题意:找字串中最长回文串的最小值的串 m=2的时候暴力打表找规律,打表可以用二进制枚举

  3. HDU 5531 Rebuild (2015长春现场赛,计算几何+三分法)

    Rebuild Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total S ...

  4. Aggregated Counting-----hdu5439(2015 长春网络赛 找规律)

    #include<stdio.h> #include<string.h> #include<iostream> #include<math.h> #in ...

  5. hdu 5512 Pagodas 扩展欧几里得推导+GCD

    题目链接 题意:开始有a,b两点,之后可以按照a-b,a+b的方法生成[1,n]中没有的点,Yuwgna 为先手, Iaka后手.最后不能再生成点的一方输: (1 <= n <= 2000 ...

  6. HDU 5512 Pagodas

    2015 ACM / ICPC 沈阳现场赛 D 题 找了一小时规律......发现是个GCD. #include<cstdio> #include<cstring> #incl ...

  7. HDU 1847 Good Luck in CET-4 Everybody!(找规律版巴什博奕)

    Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...

  8. HDU 1517 A Multiplication Game (SG函数找规律)

    题意:两个玩家玩一个游戏,从 p = 1,开始,然后依次轮流选择一个2 - 9的数乘以 p,问你谁先凑够 p >= n. 析:找规律,我先打了一下SG函数的表,然后就找到规律了 我找到的是: 1 ...

  9. Just Random HDU - 4790 思维题(打表找规律)分段求解

    Coach Pang and Uncle Yang both love numbers. Every morning they play a game with number together. In ...

随机推荐

  1. IOS数据类型

    id – 动态对象类型.动态类型和静态类型对象的否定词汇为 nil. Class – 动态类的类型.它的否定词汇为 Nil.SEL – 选择器的数据类型(typedef):这种数据类型代表运行时的一种 ...

  2. Android log日志

    LOG是用来记录程序执行过程的机制,它既可以用于程序调试,也可以用于产品运营中的事件记录.在Android系统中,提供了简单.便利的LOG机制,开发人员可以方便地使用. androidsdk中提供了l ...

  3. Android查询:模拟键盘鼠标事件(adb shell 实现)

    1. 发送键盘事件: 命令格式1:adb shell input keyevent “value” 其中value以及对应的key code如下表所列: KeyEvent Value KEYCODE ...

  4. .propertie文件注释

    在.properties文件中注释,前边加#就可以

  5. 函数fsp_header_init

    /**********************************************************************//** Initializes the space he ...

  6. UVa 12716 (GCD == XOR) GCD XOR

    题意: 问整数n以内,有多少对整数a.b满足(1≤b≤a)且gcd(a, b) = xor(a, b) 分析: gcd和xor看起来风马牛不相及的运算,居然有一个比较"神奇"的结论 ...

  7. Content-Type

    HTTP Content-type .*( 二进制流,不知道下载文件类型) application/octet-stream .txt text/plain 没有csv这种类型

  8. Python cookbook - 读书笔记

    Before: python built-in function: docs 我只想学function map(), THIS  - 摘: map(foo, seq) is equivalent to ...

  9. PL/SQL中LOOP循环控制语句

    在PL/SQL中可以使用LOOP语句对数据进行循环处理,利用该语句可以循环执行指定的语句序列.常用的LOOP循环语句包含3种形式:基本的LOOP.WHILE...LOOP和FOR...LOOP. LO ...

  10. Win10遇上Kindle就蓝屏

    在使用 Kindle 连接 Win10 时会出现蓝屏现象,现在,微软承认 Windows 10 插入 Kindle 导致蓝屏问题,并表示目前正着手制作补丁.微软表示:“我们承认确实存在当Kindle ...