HDU 1527 取石子游戏(威佐夫博弈)

来源:互联网 发布:逆战刷枪软件安卓版 编辑:程序博客网 时间:2024/06/07 07:04

取石子游戏

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4636    Accepted Submission(s): 2450


Problem Description
有两堆石子,数量任意,可以不同。游戏开始由两个人轮流取石子。游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子;二是可以在两堆中同时取走相同数量的石子。最后把石子全部取完者为胜者。现在给出初始的两堆石子的数目,如果轮到你先取,假设双方都采取最好的策略,问最后你是胜者还是败者。
 

Input
输入包含若干行,表示若干种石子的初始情况,其中每一行包含两个非负整数a和b,表示两堆石子的数目,a和b都不大于1,000,000,000。
 

Output
输出对应也有若干行,每行包含一个数字1或0,如果最后你是胜者,则为1,反之,则为0。
 

Sample Input
2 18 44 7
 

Sample Output
010
 

Source
NOI
 

Recommend
LL   |   We have carefully selected several similar problems for you:  1404 1524 1729 1730 1079 
 

Statistic | Submit | Discuss | Note


#pragma comment(linker, "/STACK:1024000000,1024000000")#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<queue>#include<stack>#include<vector>#include<set>#include<map>#define L(x) (x<<1)#define R(x) (x<<1|1)#define MID(x,y) ((x+y)>>1)#define bug printf("hihi\n")#define eps 1e-7typedef __int64 ll;using namespace std;#define INF 10005#define N 200005int main(){    int i,j,n,m;    while(~scanf("%d%d",&n,&m))    {        if(n<m) swap(n,m);        int k=n-m;        n=(int)(k*((1+sqrt(5.0))/2));        if(n==m)            printf("0\n");        else            printf("1\n");    }    return 0;}


0 0
原创粉丝点击