D - Pagodas

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" orIaka"). 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

自己设几个数模拟一下,可以发现,他们只能相差两个人的最大公约数,然后看看有奇数个还是偶数个就可以了

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<cmath>
#include<string.h>
#include<algorithm>
#define sf scanf
#define pf printf
#define pb push_back
#define mm(a,b) memset((a),(b),sizeof(a))
#include<vector>
typedef __int64 ll;
typedef long double ld;
const ll mod=1e9+7;
using namespace std;
const double pi=acos(-1.0);
int gcd(int a,int b)
{
    return b==0?a:gcd(b,a%b);
 }
bool judge(int m,int a,int b)
{
        int x=gcd(a,b);
        int num=m/x;
        if(num&1)
            return false;
        else
            return true;
}
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        int m,a,b;
        sf("%d%d%d",&m,&a,&b);
        if(judge(m,a,b))
        pf("Case #%d: Iaka\n",i);
        else
        pf("Case #%d: Yuwgna\n",i);
    }
    return 0;
}

原文地址:https://www.cnblogs.com/wzl19981116/p/9356710.html

时间: 2024-11-05 17:20:28

D - Pagodas的相关文章

2015ACM/ICPC亚洲区沈阳站-重现赛 1004 Pagodas

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 1≤a≠b≤n) withstood the test of time. Two monks, Yuwgna and

hdu5512 Pagodas(2015ACM/ICPC亚洲区沈阳站-重现赛(感谢东北大学) )

Pagodas Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 14 Accepted Submission(s): 13 Problem Description n pagodas were standing erect in Hong Jue Si between the Niushou Mountain and the Yuntai M

Pagodas(等差数列)

Pagodas Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 24    Accepted Submission(s): 22 Problem Description n pagodas were standing erect in Hong Jue Si between the Niushou Mountain and the Yun

Pagodas 等差数列

nn pagodas were standing erect in Hong Jue Si between the Niushou Mountain and the Yuntai Mountain, labelled from 11 to nn. However, only two of them (labelled aa and bb, where 1≤a≠b≤n1≤a≠b≤n) withstood the test of time. Two monks, Yuwgna and Iaka, d

HDU - 5512 Pagodas

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 mak

HDU 5512 Pagodas(等差数列)

题目戳这 题意:给你三个数:n,a,b,一开始一个集合里面有两个数:a和b,然后两个人轮流往这个集合里面增加数字,增加的这个数字的原则是,这个集合里面任选两个数的和或差,集合里面的数字不能重复,同时这个数字不能大于 n .(本来说的造塔,这样说方便一点) 思路:本来还以为是博弈,但是后来把数字的加减都模拟一遍之后发现,无论怎样,最后得到的这个集合里面的数列,其实是一个等差数列,所以这就简单了,由一开得到的 a 和 b 来相减,然后不断地取最小的两个数相减,然后等到等差数列的差,这个差同时也是等差

HDU 5512 Pagodas (gcd)

题目:传送门. 题意:t组数据,每组数据给定n,a,b,a!=b,在[1,n]的这些点中,每次选取a+b或a-b或b-a点,选取过的点在下次选取的时候可以当做ab来用继续选取,谁不能继续选取谁就输,问最后谁能赢. 题解:首先第一眼看这道题可能会想到博弈,然而这道题本质并不是博弈,而是gcd,因为选取的点一定是 gcd(a,b) 的倍数,可选取的点就是n/gcd(a,b)-2个,所以判断可选取点的奇偶性即可,如果是奇数那么先手赢,否则后手赢. #include <bits/stdc++.h> u

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

题目链接 题意:开始有a,b两点,之后可以按照a-b,a+b的方法生成[1,n]中没有的点,Yuwgna 为先手, Iaka后手.最后不能再生成点的一方输: (1 <= n <= 20000) T组数据T <= 500; 思路:由扩展欧几里得知道对于任意正整数,一定存在整数x,y使得 x*a + y*b = gcd(a,b);并且这个gcd是a,b组成的最小正整数:同时也知道了这也是两个点之间的最小距离: 之后直接求点的个数即可: ps:这道题我竟然想到了组合游戏..明显没有说双方都要用

【hdu 5512】【 2015ACM/ICPC亚洲区沈阳站】Pagodas 题意&题解&代码(C++)

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5512 题意: 给出n个点和a,b两个初始被标记的点,每次可以选取已经被标记点中的两个点 i , j 来标记新点 i+j 或 i-j,两个人轮流标记,如果谁无法标记,谁输,输出赢的人. 题解: 首先我们发现当a,b互质时,它通过以上操作,一定能标记到1号点,接着所有点都可以标记,当a,b不互质时,多写几个数找规律发现gcd(a,b)倍数的位置都可以标记到. 代码: #include<iostream