轉載: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
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.
For each test case, the first line provides the positive integer and two different integers and .
【題目大意】:已更新:(本來說的造塔遊戲,抽象成下面說更容易理解)
題意:給你三個數: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 的範圍內可以得到的數字的個數了,然後因爲分先手和後手,所以最後只要判斷一下個數的奇偶數就可以得到答案了。
代碼:
- /***************************
- * Problem: HDU No.5512
- * Running time: 0MS
- * Complier: G++
- * Author: herongwei
- * Create Time: 17:30 2015/10/31
- *****************************/
- #include <stdio.h>
- #include <string.h>
- #include <iostream>
- #include <algorithm>
- #include <queue>
- using namespace std;
- int main()
- {
- int t,tot=1;
- scanf("%d",&t);
- while(t--)
- {
- int n,a,b;
- scanf("%d%d%d",&n,&a,&b);
- int gcd=__gcd(a,b);
- int ans=n/gcd;
- printf("Case #%d: ",tot++);
- if(ans&1) puts("Yuwgna");
- else puts("Iaka");
- }
- return 0;
- }