zoukankan      html  css  js  c++  java
  • hdu 1730 Nim博弈

    题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=1730

    Nim博弈为:n堆石子,每个人可以在任意一堆中取任意数量的石子

    n个数异或值为0就后手赢,否则先手赢

    将这题转化成Nim游戏

    可以在任意一行中移动任意距离,可以向左或右,但是仔细观察发现,其实只能接近对方棋子,如果你远离对方棋子,对方可以接近你相同距离

    和nim相似的是,不能不移,所以两个棋子的距离差就是SG值

    #include<cstdio>
    #include<iostream>
    #include<cmath>
    using namespace std;
    int main()
    {
    	int n,m;
    	while(cin>>n>>m)
    	{
    		int ans=0;
    		for(int i=1;i<=n;i++)
    		{
    			int a,b;
    			scanf("%d %d",&a,&b);
    			ans^=int(abs(a-b)-1);
    		}
    		if(ans==0)cout<<"BAD LUCK!"<<endl;
    		else cout<<"I WIN!"<<endl;
    	}
    	return 0;
    }
    

      

  • 相关阅读:
    python字符串字典列表互转
    列表迭代器 ListIterator
    并发修改异常处理
    二月天 案例
    Calendar类
    Date类
    冒泡排序
    内部类
    python第三天
    Layui——checkbox使用
  • 原文地址:https://www.cnblogs.com/carcar/p/9125656.html
Copyright © 2011-2022 走看看