HDU 5512 Meeting 博弈论

Meeting

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=5512

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 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" 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: 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

HINT

题意

有n个地点,然后在a,b位置已经修建了佛塔了,每个地点,只能修建一次佛塔

然后有两个人依次修建佛塔

如果要在x位置修建佛塔,那么需要满足存在i,j位置已经修建了佛塔,且x = i + j 或者 x = i - j

谁不能修建,就谁输了

让你输出最后谁能够胜利

题解:

这是一个博弈论,看到a-b的时候,就请想到gcd……

大胆猜一猜结论…… n/gcd(a,b)的奇数和偶数

代码

#include<iostream>
#include<stdio.h>
using namespace std;

int gcd(int a,int b)
{
    return b==0?a:gcd(b,a%b);
}
int main()
{
    int t;scanf("%d",&t);
    for(int cas=1;cas<=t;cas++)
    {
        int a,b,n;
        cin>>n>>a>>b;
        int flag = n/gcd(a,b);
        if(flag%2==0)
            printf("Case #%d: Iaka\n",cas);
        else
            printf("Case #%d: Yuwgna\n",cas);
    }
}
时间: 2024-08-24 14:25:04

HDU 5512 Meeting 博弈论的相关文章

hdu 1536 S-Nim 博弈论,,求出SG&#39;函数就可以解决

S-Nim Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4975    Accepted Submission(s): 2141 Problem Description Arthur and his sister Caroll have been playing a game called Nim for some time now

HDU 4311 Meeting point-1 &amp;&amp; HDU 4312 Meeting point-2

这俩个题  题意::给出N(<1e5)个点求找到一个点作为聚会的地方,使每个点到达这里的距离最小.4311是 曼哈顿距离 4312是 切比雪夫距离: 曼哈顿距离 :大家都知道 对于二维坐标系a(xa,yb),b(xb,yb)的曼哈顿距离是abs(xa-xb)+abs(ya-yb): 看的出来这个距离和x,y 都有关,但是X,Y并不相互影响,所以可以分开计算这样,分开计算的好处如下: 如果 只给一个维度的坐标系 ,我们是不可以再什么养的复杂度的时间内处理出来呢? 大难还是很好想的先排序一下,会发现

HDU 5521.Meeting 最短路模板题

Meeting Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 3361    Accepted Submission(s): 1073 Problem Description Bessie and her friend Elsie decide to have a meeting. However, after Farmer Jo

HDU 5011 Game(博弈论)

题目地址:HDU 5011 比赛的时候看那么多人过直接傻眼了..无奈,这题是真不会做,博弈论一点不会,得好好补补了.没想到这题的代码竟然是这样..当时想了好多水的方法乱蒙也没水过去.. 代码如下: #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdlib.h> #include <math.h> #includ

HDU 5521 Meeting(虚拟节点+最短路)

Meeting Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 1358    Accepted Submission(s): 435 Problem Description Bessie and her friend Elsie decide to have a meeting. However, after Farmer Jo

【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

Hdu 5521 Meeting(建图+最短路)

题目地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=5521 思路:边数太多,不能直接建图.对于每个集合,设置一个虚拟点,对于每个集合中的点u:连一条u->S权值为0的边(点在集合中,花费为0):连一条S->u权值为w的边(从集合中一点到另一点花费w).分别计算从点1到i和从点n到i的最短路,枚举i,则ans=min( ans,max ( dist[0][i],dist[1][i] ) ). #include<queue> #i

hdu 2149Public Sale(博弈论 巴什博奕)

Public Sale Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5919    Accepted Submission(s): 3472 Problem Description 虽然不想,但是现实总归是现实,Lele始终没有逃过退学的命运,因为他没有拿到奖学金.现在等待他的,就是像FarmJohn一样的农田生涯. 要种田得有田才行

hdu 5521 Meeting(最短路)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5521 题意:有1-n共n个点,给出m个块(完全图),并知道块内各点之间互相到达花费时间均为ti.已知两人分别在点1和点n,求在哪些点相遇能使得花费时间最短.题解:显然先想到从点1和点n分别求最短路,然后枚举点找出哪些点是相遇花费时间最少的.但是这题边太多了,假设一个完全图里有x个点,那边就有x*(x-1)/2条了,必须化简其边.一个可行的办法是给每个完全图增加两个点,分别为入点和出点,入点向其中的点