练习codeforces119A. Epic Game

题目如下
A. Epic Game
time limit per test2 seconds
memory limit per test256 megabytes
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number a and Antisimon receives number b. They also have a heap of n stones. The players take turns to make a move and Simon starts. During a move a player should take from the heap the number of stones equal to the greatest common divisor of the fixed number he has received and the number of stones left in the heap. A player loses when he cannot take the required number of stones (i. e. the heap has strictly less stones left than one needs to take).

Your task is to determine by the given a, b and n who wins the game.

Input
The only string contains space-separated integers a, b and n (1 ≤ a, b, n ≤ 100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile.

Output
If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes).

题目大意
有两位玩家simon和 antisimon进行游戏,每人被分配一个固定数分别是a,b;按照回合制,两人分别对n进行n-=gcd(固定数,n),直到一方不再能进行上述操作则结束分出胜负,若simin胜出,输出1,否则输出0

题目分析
就按照题目模拟游戏进行,知道回合不再能进行

点击查看代码
#include <stdio.h>

int gcd(int a, int b){
    while(b){
        int t = a % b;
        a = b;
        b = t;
    }
    return a;
}

int main() {
    int a, b, n;
    scanf("%d%d%d", &a, &b, &n);
    int left = n;
    int turn = 0;
    int play;
    while (left){
        play = (turn % 2) ? b : a;
        left = left - gcd(play, left);
        turn++;
    }
    if(turn % 2 == 0){
    printf("1\n");
    }else{
        printf("0\n");
    }
    return 0;
}
posted @ 2025-07-08 20:15  sirro1uta  阅读(10)  评论(0)    收藏  举报