HDU 5795 A Simple Nim(SG打表找规律)——2016 Multi-University Training Contest 6
来源:互联网 发布:新媒体沟通软件 编辑:程序博客网 时间:2024/04/30 22:02
传送门
A Simple Nim
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 55 Accepted Submission(s): 32
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≤T≤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≤n≤106,1≤s[i]≤109)
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.
Author
题目大意:
有
解题思路:
这个题目首先,用
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int MAXN = 1e3+5;typedef long long LL;int sg[MAXN];int get_SG(int x){ if(sg[x]!=-1) return sg[x]; int hash[MAXN]; memset(hash, 0, sizeof(hash)); for(int i=x-1; i>=0; i--) hash[get_SG(i)]=1; for(int j=1; j<=x; j++) { for(int jj=1; jj<=x; jj++) { if(x-j-jj > 0) hash[get_SG(x-j-jj)^get_SG(j)^get_SG(jj)]=1; } } int k; for(k=0; k<MAXN; k++) { if(!hash[k]) { return sg[x] = k; } }}int main(){ /**测试打表**/ /*memset(sg,-1,sizeof(sg)); for(int i=0; i<50; i++) { printf("sg[%d] = %d\n",i,get_SG(i)); }*/ int T; cin>>T; while(T--) { int m; LL ans = 0; cin>>m; while(m--) { LL x; cin>>x; if(x%8==0) ans ^= (x-1); else if(x%8 == 7) ans ^= (x+1); else ans ^= x; } if(ans) puts("First player wins."); else puts("Second player wins."); } return 0;}
0 0
- HDU 5795 A Simple Nim(SG打表找规律)——2016 Multi-University Training Contest 6
- (HDU 5795)2016 Multi-University Training Contest 6 A Simple Nim (SG函数、博弈)
- hdu 5795 A Simple Nim(2016 Multi-University Training Contest 6——博弈)
- 2016 Multi-University Training Contest 6 1003 A Simple Nim (博弈sg函数)
- hdu 5795 2016 Multi-University Training Contest 6(SG+打表找规律)
- HDU 5399 Too Simple(数学 + 找规律)——2015 Multi-University Training Contest 9
- HDU 5795 A Simple Nim(SG打表找规律)
- hdu 5795 A Simple Nim(SG打表找规律)
- 尼姆博奕HDU 5795 A Simple Nim(SG打表找规律)
- HDU 5826 physics(积分 找规律)——2016 Multi-University Training Contest 8
- 2016 多校 Multi-University Training Contest 6 A Simple Chess
- 【2016 Multi-University Training Contest 6】【1002】【A Simple Chess】
- (HDU 5793)2016 Multi-University Training Contest 6 A Boring Question (规律)
- HDU 5810 Balls and Boxes(打表找规律)——2016 Multi-University Training Contest 7 1002
- (HDU 5794)2016 Multi-University Training Contest 6 A Simple Chess (Lucas、容斥)
- HDU 5795 A Simple Nim SG函数打表找规律
- HDU-5795 A Simple Nim(SG函数打表找规律)
- HDU 5795 A Simple Nim (SG函数+打表找规律)
- 网页自适应浏览器方法收录
- Maven多模块项目介绍和搭建
- 文章折叠
- Git的安装、配置;使用它上传、下载
- 页面加载百度地图
- HDU 5795 A Simple Nim(SG打表找规律)——2016 Multi-University Training Contest 6
- 运行caffe自带的两个例子
- javascript touch事件
- 修改angular post提交json数据的格式_ $httpProvider配置
- oc语言类 便利初始化函数 便利构造器 属性
- hdu 4545 魔法串 (模拟)
- tmpl 模板化引擎加载数据 Jquery
- 饼图与柱状图的topN处理
- 关于mybatis扫描所有namespace时报错,最终原因是resultMap不能使用(我的错误记录)