hdu 5512 (Pagodas) 2015 ACM/ICPC 亚洲区沈阳赛区 (题目编号1004)

34 篇文章 0 订阅
20 篇文章 4 订阅
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 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: 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

题意:

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

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

比如:

例1,有3个寺庙,a=1,b=2;则Yuwgna只能修第三个;那么Yuwgna赢;

例2,有6个寺庙,编号1 2 3 4 5 6,a=2,b=3,则Yuwgna只能修第一个或第五个,若Yuwgna修了第一个,则Iaka可以修第四个,依次类推。

思路:

看完题意,果断判定博弈,然后各种找规律,if-else判断写了五六个,交了六七遍,结果全wa;

最后一直调bug,发现当寺庙个数为6时,若a=3,b=6;则Yuwgna没有寺庙可修建;

然后加了个判断:处理b/a=2的时候,每次只能修a的整数倍,提交还是wa;

之后又找到一个bug:当个数为12时,a=9,b=12;则3,6都可以取到;

最后终于想到a和b的最大公约数;先求a和b的最大公约数c,则c的整数倍都可以取到;比如有16个庙,a=8,b=12;则4和16可以取到;

以下是ac代码:

#include <stdio.h>
int f(int a,int b)
{                       //求最大公约数
    int temp,r;
    if (a<b)
    {
        temp=a;
        a=b;
        b=temp;
    }
    r=a%b;
  while(r)
  {
      a=b;
      b=r;
      r=a%b;
  }
  return b;
}
int main ()
{
    int t;
    int n,i,a,b;
    int j,sum;
    int k;
    scanf ("%d",&t);
    for (i=1;i<=t;i++)
    {
        k=0;
        scanf ("%d%d%d",&n,&a,&b);
        sum=f(a,b);
        for (j=sum;j<=n;j+=sum)     //j每次加的是a和b的最大公约数
            k++;
        k-=2;
    if (k%2==0)
        printf ("Case #%d: Iaka\n",i);
    else
        printf ("Case #%d: Yuwgna\n",i);
    }
    return 0;
}






  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值