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;
}
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;
}
相关文章推荐
- Codeforces Beta Round #90, problem: (C) Education Reform DP
- Codeforces Beta Round #90 C. Education Reform
- Codeforces Beta Round #90 C题
- Codeforces Beta Round #35 (Div. 2) E. Parade(成段更新)
- Codeforces Beta Round #1 A. Theatre Square
- Codeforces Beta Round #13 E. Holes (分块)
- Codeforces Beta Round #34 (Div. 2) A题 B题 C题(水水~)
- Codeforces Beta Round #62 题解【ABCD】
- Codeforces Beta Round #92 (Div. 2 Only) B. Permutations
- Codeforces Beta Round #63 (Div. 2)
- Codeforces Beta Round #1 A. Theatre Square
- 由codeforces beta round 1 总结的一些知识
- Codeforces Beta Round #73 (Div. 2 Only)——A,B,C
- Codeforces Beta Round #5——C. Longest Regular Bracket Sequence
- Codeforces Beta Round #50 C. First Digit Law(概率dp,好题)
- Codeforces Beta Round #95
- Codeforces Beta Round #14 (Div. 2) D. Two Paths 树形dp
- Codeforces Beta Round #18 (Div. 2 Only) D - Seller Bob
- Codeforces Beta Round #92 (Div. 2 Only) B. Permutations 模拟
- Codeforces Beta Round #75 (Div. 1 Only) A题