您的位置:首页 > 其它

HDU_1730 Northcott Game(博弈)

2015-08-10 15:02 295 查看
题目请点我

题解:

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

代码实现:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#define MAX 1010

using 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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  博弈