HDU 5795 A Simple Nim (SG函数+打表找规律)
来源:互联网 发布:应聘淘宝客服被骗 编辑:程序博客网 时间:2024/05/17 20:23
A Simple Nim
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1129 Accepted Submission(s): 637
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
224 431 2 4
Sample Output
Second player wins.First player wins.
Author
UESTC
Source
2016 Multi-University Training Contest 6
POINT:
游戏的和的SG函数值是它的所有子游戏的SG函数值的异或(重要!!)
#include <iostream>#include <cstdio>#include <cstring>using namespace std;#define ll long long/*int sg[10005]= {0,1,2};//打表int vis[10005];void play(){ for(int i=3;i<=100;i++) { memset(vis,0,sizeof vis); for(int j=1;j<=i;j++) { for(int k=1;k<=i;k++) { if(j+k<i) { vis[sg[j]^sg[k]^sg[i-j-k]]=1; } } } for(int j=0;j<i;j++) { vis[sg[j]]=1; } for(int j=0;;j++) { if(!vis[j]) { sg[i]=j; break; } } } for(int i=0;i<=100;i++) { printf("%d %d\n",i,sg[i]); }}*/ll sg(ll n){ if(n%8==0) return n-1; else if((n+1)%8==0) return n+1; else return n;}int main(){ // play(); int T; scanf("%d",&T); while(T--) { int n; scanf("%d",&n); ll res=0; while(n--) { ll a; scanf("%lld",&a); res=res^sg(a); } if(res==0) printf("Second player wins.\n"); else printf("First player wins.\n"); } return 0;}
阅读全文
0 0
- HDU 5795 A Simple Nim SG函数打表找规律
- HDU-5795 A Simple Nim(SG函数打表找规律)
- HDU 5795 A Simple Nim (SG函数+打表找规律)
- HDU 5795 A Simple Nim (找规律+sg函数+博弈)
- HDU 5795 A Simple Nim(SG打表找规律)
- hdu 5795 A Simple Nim(SG打表找规律)
- 尼姆博奕HDU 5795 A Simple Nim(SG打表找规律)
- HDU-5795-A Simple Nim-博弈(SG函数)打表找规律
- hdu 5795 A Simple Nim (sg函数)
- hdu5795A Simple Nim(SG函数、打表找规律)
- HDU 5795 A Simple Nim 详解(SG打表找规律,博弈好题)
- hdu 5795A Simple Nim SG函数(多校)
- HDU 5795 A Simple Nim (sg函数 打表)
- 【hdu 5795】A Simple Nim sg函数+脑洞+观察
- HDU 5795 A simple Nim [SG]【博弈】
- HDU 5795 A Simple Nim(SG打表找规律)——2016 Multi-University Training Contest 6
- 【博弈+SG函数+打表找规律】HDU_5795_A Simple Nim
- HDU 5795 A Simple Nim(Nim游戏博弈+SG函数)
- 网间互联-国家级互联网骨干直联点
- MySQL 5.7.18 安装教程
- Linux-用shell脚本写一个进度条
- NGUI学习要点总结
- 策略模式
- HDU 5795 A Simple Nim (SG函数+打表找规律)
- vuex学习笔记
- 朱金付C++第五章
- (三)Redux:创建和使用Reducer
- 嵌入人生
- 刷题记录-luoguP1525 关押罪犯
- 小白学爬虫-----bs4的学习-1
- 【HNOI2016模拟4.4】Alphadog
- JS编程训练 | 题14:正确函数定义