您的位置:首页 > 编程语言 > C语言/C++

HDU 1730 Northcott Game(nim博弈)

2014-09-16 14:19 465 查看
题目地址:HDU 1730

由于每次如果黑方向左移动棋子,白方都可以在同行的白色棋子向左移动相同的距离,对结果没影响。所以转换成了一个nim游戏。

代码如下:

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <queue>
#include <map>
#include <set>
#include <algorithm>

using namespace std;
int main()
{
int n, m, a, b, sum;
while(scanf("%d%d",&n,&m)!=EOF)
{
sum=0;
while(n--)
{
scanf("%d%d",&a,&b);
if(a>b) swap(a,b);
sum^=b-a-1;
}
if(sum)
puts("I WIN!");
else
puts("BAD LUCK!");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息