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 的範圍內可以得到的數字的個數了,然後因爲分先手和後手,所以最後只要判斷一下個數的奇偶數就可以得到答案了。

代碼:

  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. }  
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章