HDU_1730 Northcott Game(博弈)

来源:互联网 发布:西瓜影音播放器mac版 编辑:程序博客网 时间:2024/06/06 02:48

题目请点我
题解:
这是一道变形的Nim博弈问题,将每次两棋子中间相差的格数当作一堆棋子,谁取走最后一个(留给对方一个必败态),谁就获胜。转换为了Nim问题,最后直接套公式就好了。
代码实现:

#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#define MAX 1010using namespace std;int N,M;int sum;int res;int main(){    //freopen("in.txt","r",stdin);    while( scanf("%d%d",&N,&M) != EOF ){        int a,b;        res = 0;        for( int i = 0; i < N; i++ ){            scanf("%d%d",&a,&b);            res ^= abs(a-b)-1;        }        if( res == 0 ){            printf("BAD LUCK!\n");        }        else{            printf("I WIN!\n");        }    }    return 0;}
0 0
原创粉丝点击