HDU 5512 Pagodas (GCD 博弈)

来源:互联网 发布:基于大数据用户画像 编辑:程序博客网 时间:2024/06/05 02:59

Pagodas

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


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 aand b, where 1abn) 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 1in) if there exist two pagodas standing erect, labelled j and k respectively, such that i=j+k or i=jk. 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 (1t500) which is the number of test cases.
For each test case, the first line provides the positive integer n (2n20000) 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
162 1 23 1 367 1 2100 1 28 6 89 6 810 6 811 6 812 6 813 6 814 6 815 6 816 6 81314 6 81994 1 131994 7 12
 

Sample Output
Case #1: IakaCase #2: YuwgnaCase #3: YuwgnaCase #4: IakaCase #5: IakaCase #6: IakaCase #7: YuwgnaCase #8: YuwgnaCase #9: IakaCase #10: IakaCase #11: YuwgnaCase #12: YuwgnaCase #13: IakaCase #14: YuwgnaCase #15: IakaCase #16: Iaka
 

Source
2015ACM/ICPC亚洲区沈阳站-重现赛(感谢东北大学)
 
题意:给数据范围,最初有两个数a,b建塔,2人可选(i,j有塔)i-j,j+i建塔,无法取的输;

显然能够建的的位置在gcd(a,b)的倍数上,所以能建的位置有n/gcd(a,b) - 2个,

判断奇偶因为%2,-2无影响

#include <iostream>#include <algorithm>#include <cstring>#include <cstdio>#include <stack>#include <cmath>#include <queue>#include <map>using namespace std;#define N 2100int n,a,b;int T;int main(){    scanf("%d",&T);    for(int i=1;i<=T;i++)    {        scanf("%d%d%d",&n,&a,&b);        int d=__gcd(a,b);        d=n/d;        if(d%2 == 0)            printf("Case #%d: Iaka\n",i);        else             printf("Case #%d: Yuwgna\n",i);    }    return 0;}



原创粉丝点击