HDU 5512 Pagodas

转载:https://blog.csdn.net/u013050857/article/details/49534677

找规律的题目:

Pagodas

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


Problem Description
 pagodas were standing erect in Hong Jue Si between the Niushou Mountain and the Yuntai Mountain, labelled from  to . However, only two of them (labelled and , where ) 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  if there exist two pagodas standing erect, labelled  and  respectively, such that  or . 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  which is the number of test cases.
For each test case, the first line provides the positive integer  and two different integers  and .
 

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

【题目大意】:已更新(本来说的造塔游戏,抽象成下面说更容易理解)

题意:给你三个数:n,a,b,一开始集合里面有两个数:a和b,然后两个人轮流往这个集合里面增加数字,增加的这个数字的原则是:这个集合里面任选两个数的和或差(a + b或a - b或b -a的中的任意一个没被选中的符合[1,n]的点 ),集合里面的数字不能重复,同时这个数字不能大于 n ,求最后哪个人选不了满足条件的数了。

【思路】(n/gcd(a,b)&1)即可,为什么这样说呢?思考一下:a + b或a - b或b -a这样的数次操作之后,无论怎样,最后得到的这个集合里面的数列,其实是一个等差数列,想到这这就简单了,由最开始的 a 和 b 来相减,不断地取最小的两个数相减,然后等到等差数列的差,这个差同时也是等差数列的首项(即为gcd(a,b)),然后拿 n 除以这个差就是在 n 的范围内可以得到的数字的个数了,然后因为分先手和后手,所以最后只要判断一下个数的奇偶数就可以得到答案了。

代码:

[cpp]  view plain  copy
  1. /*************************** 
  2. * Problem: HDU No.5512 
  3. * Running time: 0MS   
  4. * Complier: G++   
  5. * Author: herongwei  
  6. * Create Time: 17:30 2015/10/31  
  7. *****************************/    
  8. #include <stdio.h>  
  9. #include <string.h>  
  10. #include <iostream>  
  11. #include <algorithm>  
  12. #include <queue>  
  13. using namespace std;  
  14.   
  15. int main()  
  16. {  
  17.      int t,tot=1;  
  18.      scanf("%d",&t);  
  19.      while(t--)  
  20.      {  
  21.          int n,a,b;  
  22.          scanf("%d%d%d",&n,&a,&b);  
  23.          int gcd=__gcd(a,b);  
  24.          int ans=n/gcd;  
  25.          printf("Case #%d: ",tot++);  
  26.          if(ans&1) puts("Yuwgna");  
  27.          else  puts("Iaka");  
  28.      }  
  29.      return 0;  
  30. }  

猜你喜欢

转载自blog.csdn.net/ZLucker/article/details/80382176
hdu