博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU5795A Simple Nim SG定理
阅读量:4658 次
发布时间:2019-06-09

本文共 1787 字,大约阅读时间需要 5 分钟。

A Simple Nim

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 980    Accepted Submission(s): 573

Problem Description
Two players take turns picking candies from n heaps,the player who picks the last one will win the game.On each turn they can pick any number of candies which come from the same heap(picking no candy is not allowed).To make the game more interesting,players can separate one heap into three smaller heaps(no empty heaps)instead of the picking operation.Please find out which player will win the game if each of them never make mistakes.
 
Input
Intput contains multiple test cases. The first line is an integer $1\le T\le 100$, the number of test cases. Each case begins with an integer n, indicating the number of the heaps, the next line contains N integers $s[0],s[1], ....,s[n-1]$, representing heaps with $s[0],s[1], ...,s[n-1]$ objects respectively.$(1\le n\le 10^6,1\le s[i]\le 10^9)$
 
Output
For each test case,output a line whick contains either"First player wins."or"Second player wins".
 
Sample Input
2
2
4 4
3
1 2 4
 
Sample Output
Second player wins.
First player wins.
 
题意:n堆石子,两个人轮流拿,每次可以选择任意一堆取任意个(不能不拿)或者将一个堆分成3个小堆,问先手胜还是后手胜。
题解:SG定理的应用,可以看做是Nim博弈,打表找规律,我也不会证
  i=8*k+7时SG[i]=8*k+8,i=8*k+8时SG[i]=8*k+7其他情况SG[i]=i。
#include
#define N 45000#define mes(x) memset(x, 0, sizeof(x));#define ll __int64const long long mod = 1e9+7;const int MAX = 0x7ffffff;using namespace std;int dir[200], SG[200];int getSG(int n){ if(n == 0) return 0; if(n%8 == 0) return n-1; if(n%8 == 7) return n+1;//注意这里是n%8==7,不是n%7==0.... return n;}int main(){ int T,t, i,n, ans; scanf("%d", &T); while(T--){ scanf("%d", &n); for(ans=i=0;i

 

转载于:https://www.cnblogs.com/Noevon/p/6241226.html

你可能感兴趣的文章
hdu 4542 小明系列故事——未知剩余系
查看>>
Symbian UI 架构分类
查看>>
SVM入门(三)线性分类器Part 2
查看>>
mysql 执行 cannot found mac安装mysql的两种方法(含配置)
查看>>
BZOJ 1984: 月下“毛景树”( 树链剖分 )
查看>>
Properties类、序列化流与反序列化流
查看>>
Swift学习笔记一:与OC的区别
查看>>
七牛容器实操
查看>>
理解 YOLO
查看>>
检查Linux文件变更Shell脚本
查看>>
ActiveMQ中JMS的可靠性机制
查看>>
oracle操作字符串:拼接、替换、截取、查找
查看>>
”语义“的理解
查看>>
210. Course Schedule II
查看>>
月薪3000与月薪30000的文案区别
查看>>
使用spring dynamic modules的理由
查看>>
Leetcode 117 Populating Next Right Pointers in Each Node 2
查看>>
C++ Primer 第四版中文版
查看>>
变量关系
查看>>
NTP工作机制及时间同步的方法
查看>>