HDU5512 Pagodas(GCD+水题)
来源:互联网 发布:php微信分销开源系统 编辑:程序博客网 时间:2024/06/05 03:07
Pagodas
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1742 Accepted Submission(s): 1198
Problem Description
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
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 integern (2≤n≤20000) and two different integers a and b .
For each test case, the first line provides the positive integer
Output
For each test case, output the winner (``Yuwgna" or ``Iaka"). Both of them will make the best possible decision each time.
Sample Input
162 1 23 1 367 1 2100 1 28 6 89 6 810 6 811 6 812 6 813 6 814 6 815 6 816 6 81314 6 81994 1 131994 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
题意:给定n和a,b,分别代表有1到n所房子要建,每次只能建|a-b|或a+b编号的房子,a,b编号的房子已经存在不能再建,由Yuwgna先建,Iaka后建,谁先建不了谁输,输出赢的人的名字
思路:因为只能建a-b和a+b的房子,所以能建的房子的编号应该是gcd(a,b)的倍数那么所有能建的房子数应该是n/gcd(a,b)-2又因为是Yuwgna先建,且只有两个人建,所以n/gcd(a,b)-2对2取模,若等于0,则Yuwgna最后不能再建,Iaka赢,反之Iaka输Yuwgna赢
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int gcd(int a,int b){ return b?gcd(b,a%b):a;}int main(){ int t; scanf("%d",&t); int cas=1; while(t--) { int n,a,b; scanf("%d%d%d",&n,&a,&b); if(gcd(a,b)==1) { if(n%2==0) printf("Case #%d: Iaka\n",cas++); else printf("Case #%d: Yuwgna\n",cas++); } else { if((n/gcd(a,b)-2)%2==0) printf("Case #%d: Iaka\n",cas++); else printf("Case #%d: Yuwgna\n",cas++); } } return 0;}
阅读全文
0 0
- HDU5512 Pagodas(GCD+水题)
- HDU5512 Pagodas(GCD)
- hdu5512 Pagodas 规律题 gcd
- HDU5512 Pagodas
- hdu5512-Pagodas
- HDU5512 Pagodas
- HDU5512--Pagodas
- HDU5512 Pagodas(博弈)
- HDU5512(Pagodas)
- HDU5512 Pagodas (欧几里得)
- 【HDU5512 2015沈阳赛区D】【签到题 gcd博弈】Pagodas 取数x+y或x-y
- 【hdu5512 规律】Pagodas icpc2015·沈阳
- HDU 5512 Pagodas (水题+GCD )
- HDU5512(水题~)
- HDU-5512 Pagodas(GCD)
- hdoj 5512 Pagodas (gcd)
- HDU 5512 Pagodas(GCD)
- hdu 5512 Pagodas gcd()
- springmvc 的静态资源配置
- 《机器学习技法》学习笔记13——深度学习
- 二叉树 STL 图 哈希 详解
- Editor does not contain a main type
- JS事件处理程序的几种方法
- HDU5512 Pagodas(GCD+水题)
- UVa11582 [快速幂]Colossal Fibonacci Numbers!
- php &
- Shell常见命令实践
- CodeForces
- springBoot如何如何设置fileMazSize()
- ZOJ 1525 Air Raid (有向图最小路径覆盖 + 理解)
- HDU 6071 Lazy Running
- POJ 2409 Let it Bead(polya染色问题)