标签:
Time Limit: 20 Sec
Memory Limit: 256 MB
http://acm.hdu.edu.cn/showproblem.php?pid=5512
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
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位置已经修建了佛塔了,每个地点,只能修建一次佛塔
然后有两个人依次修建佛塔
如果要在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); } }
标签:
原文地址:http://www.cnblogs.com/qscqesze/p/4929923.html