您的位置:首页 > 其它

Codeforces Beta Round #90 A题

2013-06-22 16:14 197 查看
这道题目我们不用看题目什么意思就可以做了,只要看这里:

Note

The greatest common divisor of two non-negative integers a and b is
such maximum positive integer k, that a is divisible
by k without remainder and similarly, b is divisible
by k without remainder. Let gcd(a, b) represent
the operation of calculating the greatest common divisor of numbers a and b.
Specifically, gcd(x, 0) = gcd(0, x) = x.

In the first sample the game will go like that:

Simon should take gcd(3, 9) = 3 stones from the heap. After his move the heap has 6 stones
left.

Antisimon should take gcd(5, 6) = 1 stone from the heap. After his move the heap has 5 stones
left.

Simon should take gcd(3, 5) = 1 stone from the heap. After his move the heap has 4 stones
left.

Antisimon should take gcd(5, 4) = 1 stone from the heap. After his move the heap has 3 stones
left.

Simon should take gcd(3, 3) = 3 stones from the heap. After his move the heap has 0 stones
left.

Antisimon should take gcd(5, 0) = 5 stones from the heap. As 0 < 5,
it is impossible and Antisimon loses.

In the second sample each player during each move takes one stone from the heap. As n is even, Antisimon takes the last stone and Simon can't make a move
after that.

这里很清楚的解释了我们要干嘛!先写一个gcd函数,然后循环下去,一直遇到Antisimon should take gcd(5, 0) = 5 stones
from the heap. As 0 < 5,

it is impossible and Antisimon loses.

就知道结果了,代码如下:

#include <iostream>

#include <cstdio>

#include <cstring>

using namespace std;

int gcd(int a,int b)

{

int temp,c,d;

while(b)

{

d=a%b;

a=b;

b=d;

}

return a;

}

int main()

{

int n,m,p,sum;

scanf("%d%d%d",&n,&m,&p);

while(1)

{

sum=gcd(n,p);

if(sum>p){printf("1\n") ;break;}

p-=sum;

sum=gcd(m,p);

if(sum>p){printf("0\n");break;}

p-=sum;

}

return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: