codeforces Epic Game 题解

本文介绍了一个简单的游戏策略模拟问题,玩家Simon和AntiSimon轮流从一堆石头中取走数量等于各自固定数值与剩余石头数的最大公约数的石头。文章通过示例说明了如何通过模拟的方式判断哪位玩家最终获胜。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives numberaand Antisimon receives numberb. They also have a heap ofnstones. 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 hasstrictlyless stones left than one needs to take).

Your task is to determine by the givena,bandnwho wins the game.

Input

The only string contains space-separated integersa,bandn(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).

Sample test(s)
input
3 5 9
output
0
input
1 1 100
output
1

这样的题目一般都可以找公式的,但是本题却是找不到什么好的公式了。

只有暴力去模拟玩这个游戏了。还好因为其数据不大,故此也许出题者也是没有公式的。


namespace{

	int GCD(int a, int b)
	{
		if (1 == a || b == 1) return 1;
		while (b)
		{
			int t = b;
			b = a%b;
			a = t;
		}
		return a;
	}
}

void EpicGame()
{
	int a, b, c, d;
	cin>>a>>b>>c;
	bool goGame = 0;
	while (c >= 0)
	{
		if (goGame) d = GCD(b, c);
		else d = GCD(a, c);
		c -= d;
		goGame = !goGame;
	}
	cout<<goGame;
}





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值