【HDU3032】【Lasker's Nim(一种Nim游戏)】Nim or not Nim? Multi-SG博弈、打表
2015-01-12 22:39
507 查看
转载请注明出处:http://blog.csdn.net/vmurder/article/details/42652745
其实我就是觉得原创的访问量比未授权盗版多有点不爽233。。。
题意:n堆石子,每次可以从某堆中拿走若干,也可以把此堆分成两个非空堆,谁无法操作了谁输。
题解:首先我们可以打个SG函数来暴力出解,但是显然这会T。
但是不要害怕,我们打完以后发现了一个貌似对的规律:
对于所有的k >= 0,有 sg( 4k+1 ) = 4k+1; sg(
4k+2 ) = 4k+2; sg( 4k+3 ) = 4k+4; sg( 4k+4 ) = 4k+3。
好了,可以快速出解了。
代码:
其实我就是觉得原创的访问量比未授权盗版多有点不爽233。。。
题意:n堆石子,每次可以从某堆中拿走若干,也可以把此堆分成两个非空堆,谁无法操作了谁输。
题解:首先我们可以打个SG函数来暴力出解,但是显然这会T。
但是不要害怕,我们打完以后发现了一个貌似对的规律:
对于所有的k >= 0,有 sg( 4k+1 ) = 4k+1; sg(
4k+2 ) = 4k+2; sg( 4k+3 ) = 4k+4; sg( 4k+4 ) = 4k+3。
好了,可以快速出解了。
代码:
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; int main() { int T,n,k,x; for(scanf("%d",&T);T--;) { for(k=0,scanf("%d",&n);n--;) { scanf("%d",&x); if(x%4==0)k^=(x-1); else if(x%4==3)k^=(x+1); else k^=x; } if(k)puts("Alice"); else puts("Bob"); } }
相关文章推荐
- HDU 3032 Nim or not Nim?(博弈 SG打表找规律)
- HDU 3032 Nim or not Nim?(博弈,SG打表找规律)
- HDU 3032 Nim or not Nim?(Multi_SG,打表找规律)
- HDOJ3032 Nim or not Nim? (sg打表)
- HDU 3032 Nim or not Nim? [Multi-SG]
- hdu 3032 Nim or not Nim? (SG打表找规律)
- HDU 3032 Nim or not Nim? && HDU 5795 A Simple Nim (Lasker's Nim游戏、SG函数、取走-分割游戏)
- HDU 3032 Nim or not Nim?(博弈,打表找规律)
- HDOJ 3032 Nim or not Nim? (博弈 :SG)
- HDU3032 Nim or not Nim? 博弈
- HDU 3032 Nim or not Nim? SG打表找规律
- [HDU3032]Nim or not Nim?(博弈Multi-SG游戏)
- HDU 2311-Nim or not Nim?(Nim博弈-打sg表找规律)
- Bean property 'RegDao' is not writable or has an invalid setter method. Does the parameter type of t
- Could not load file or assembly 'XXX' or one of its dependencies.
- 用命令连接mysql , 出现'mysql' is not recognized as an internal or external command错误解决
- Spring配置文件加载时出现Bean property 'newscontentDAO' is not writable or has an invalid setter method错误的解决
- 经典的Nim游戏 博弈经典模型 UVa 10404 - Bachet's Game
- jspsmartupload Files' name is invalid or does not exist的解决方法
- Could not load file or assembly 'Microsoft.Office.Interop.Excel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e94