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

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


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

 

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

 

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

 

Sample Input
2 1 8 4 4 7
 

 

Sample Output
0 1 0
 

 

Source
 

 

Recommend
LL   |   We have carefully selected several similar problems for you:  1404 1536 1517 1524 1729 
 
 
威佐夫博弈
没有前一个毒瘤
直接套公式
 
#include<cstdio>
#include<cmath>
using namespace std;
const  int MAXN=1e6+10;
int swap(int &x,int &y){int t=x;x=y;y=t;}
main()
{
    #ifdef WIN32
    freopen("a.in","r",stdin);
    #else
    #endif
    int x,y;
    while(scanf("%d%d",&x,&y)!=EOF)
    {
        if(x>y) swap(x,y);
        int temp=y-x;
        double k=(sqrt(5)+1)/2;
        int ans=temp*k;
        puts(ans==x?"0":"1");
    } 
    return 0;
}

 

posted @ 2018-02-25 08:24  自为风月马前卒  阅读(526)  评论(0编辑  收藏  举报

Contact with me