hdu5512-Pagodas

题目大意:

有n个庙经过长时间风吹雨打需要修补,只有两座(被标记为a,b)完好无损不需要修补,有两个和尚轮流去修补这n-2个庙,每个和尚每次只能修补一个庙标记为i,并要求i满足i=j+k或者i=j-k,每个庙只能被修建一次;

其中j和k代表已经修建好的庙,Yuwgna先开始,问最后谁不能修建谁输;

思路:一看题目博弈论,后来就是找 m, n 的最大公约数

#include <iostream>
#include <cstdio>
using namespace std;

int gcd(int a, int b)
{
    if(b > 0)
        return gcd(b, a%b);
    return a;
}

int main()
{
//    freopen("test.txt", "r", stdin);
    int t;
    scanf("%d", &t);
    for(int i = 1; i<= t; i++)
    {
        int n, a, b;
        scanf("%d%d%d", &n, &a, &b);
        printf("Case #%d: ", i);
            int q = gcd(a, b);
            if(q == 1)
            {
                if(n%2 == 0)
                printf("Iaka\n");
                else{
                printf("Yuwgna\n");
                }
            }
            else{
                q = n/q;
                if(q%2 == 0)
                printf("Iaka\n");
                else{
                printf("Yuwgna\n");
                }
            }

    }
    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-10-24 14:09:44

hdu5512-Pagodas的相关文章

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

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

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

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 mak

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