PagodasTime 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 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 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
Sample Output
|
题意:给定n个位置(1 — n),每个位置只能建造一个塔。现在位置a和b已经建好了塔,已知每次可以新建塔的前提——能够找到两个塔j和k使得 i = j-k || i = j+k。
现在给出一个博弈局面,当某个人不能再建造塔时为输。问你谁能赢。
思路:当且仅当 a和b处于某个等差数列(差值不为1)时,才无法使得所有位置都建上塔。相反,则n个位置均可建塔。等差数列的差值 d = gcd(a, b),求出可以建塔的个数就可以了。
AC代码:
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#define lson o<<1|1, l, mid
#define rson o<<1, mid+1, r
#define ll o<<1
#define rr o<<1|1
#define INF 0x3f3f3f3f
#define eps 1e-8
#define debug printf("1\n")
#define MAXN 100010
#define MAXM 20000000
#define LL long long
#define CLR(a, b) memset(a, (b), sizeof(a))
#define W(a) while(a--)
#define Ri(a) scanf("%d", &a)
#define Pi(a) printf("%d\n", (a))
#define Rl(a) scanf("%lld", &a)
#define Pl(a) printf("%lld\n", (a))
#define Rs(a) scanf("%s", a)
#define Ps(a) printf("%s\n", (a))
#define MOD 1000000007
#define LL long long
using namespace std;
int gcd(int a, int b){
return b == 0 ? a : gcd(b, a%b);
}
int main()
{
int t, kcase = 1;
Ri(t);
W(t)
{
int n, a, b;
Ri(n), Ri(a), Ri(b);
int temp = gcd(a, b);
int num = n / temp - 2;
if(num & 1)
printf("Case #%d: Yuwgna\n", kcase++);
else
printf("Case #%d: Iaka\n", kcase++);
}
return 0;
}