HDU 5512(GCD性质)
来源:互联网 发布:ps美工教程 编辑:程序博客网 时间:2024/06/14 23:18
Pagodas
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1571 Accepted Submission(s): 1091
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
题意:开始有a,b两点,之后可以按照a-b,a+b的方法生成[1,n]中没有的点,Yuwgna 为先手, Iaka后手。最后不能再生成点的一方输;
思路:由扩展欧几里得知道对于任意正整数,一定存在整数x,y使得 x*a + y*b = gcd(a,b);并且这个gcd是a,b组成的最小正整数;同时也知道了这也是两个点之间的最小距离。所以可修建塔的编号为 gcd(a,b)*k (1<=k<=n/k)。
之后直接求点的个数即可;
代码:#include<bits/stdc++.h>using namespace std;int main(){ int T,n,l,r; scanf("%d",&T); for(int kase = 1;kase <= T;kase++){ scanf("%d%d%d",&n,&l,&r); int gcd = __gcd(l,r); int cnt = n/gcd; printf("Case #%d: %s\n",kase,cnt&1?"Yuwgna":"Iaka"); } return 0;}
阅读全文
0 0
- HDU 5512(GCD性质)
- hdu-4497-GCD and LCM-gcd的性质
- GCD and LCM+hdu+利用gcd和lcm的性质
- hdu5019(gcd性质水题)
- hdu 4497 (gcd和lcm的性质+排列组合)
- HDU 5869 树状数组+GCD性质的利用
- HDU 5512 Pagodas (gcd)
- gcd的一些性质
- HDU 5512 Pagodas (简单博弈 gcd)
- HDU 5512 Pagodas (水题+GCD )
- HDU 5512 Pagodas (GCD 博弈)
- HDU-5512 Pagodas(GCD)
- HDU 5512 Pagodas(GCD)
- hdu 5512 Pagodas gcd()
- HDOJ 题目4497 GCD and LCM (组合数学,gcd性质)
- HDU 2504 又见GCD(gcd)
- HDU 5902:GCD is Funny (GCD)
- Hdu-5902-GCD is Funny (gcd)
- java错题mark_2
- 创建静态ip,并使A类私有地址能ping通外网
- 多选框
- 打造云上代码交付链_CodePipeline实践分享
- Android_动画机制
- HDU 5512(GCD性质)
- 英语总结系列(三十):开阔视野
- 进入主页Activity的淡入淡出动画效果
- 分布式事务处理解决方案
- Android中Context详解 ---- 你所不知道的Context
- 手机归属地查询
- 企业级互联网架构(Aliware)实践
- 负载均衡-nginx
- 盘点8种CSS实现垂直居中水平居中的绝对定位居中技术