6

2015ACM-ICPC亚洲区域赛沈阳站 D:Pagodas

 3 years ago
source link: https://arminli.com/acm-shenyang-d/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Armin's Blog

2015ACM-ICPC亚洲区域赛沈阳站 D:Pagodas

March 09, 2016

题目链接

题意:N 个点,刚开始给出两个点 a,b(a != b) ,有两个人玩一个游戏,游戏规则如下:每次只能选择 a + b 或 a - b 或 b -a 的中的任意一个没被选中的符合[1,n]的点 。问最后谁一个点也选不了了。

能被选的点其实只有 n / GCD(a,b),因为初始的 a 和 b 决定了塔的间距,最后只要判奇偶即可。

#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int gcd(int a, int b){
    return b == 0 ? a : gcd(b, a % b);
}

int main(){
    int cas;
    scanf("%d", &cas);
    for (int t = 1; t <= cas; t++) {
        int n, a, b;
        scanf("%d%d%d", &n, &a, &b);
        int d = n / gcd(a, b);
        printf("Case #%d: %s\n", t, d&1 ? "Yuwgna" : "Iaka");
    }
    return 0;
}

Profile picture

Written by Armin Li , a venture capitalist. [Weibo] [Subscribe]


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK