hdu5795 A Simple Nim(博弈找规律)
来源:互联网 发布:小学测验软件 编辑:程序博客网 时间:2024/04/29 08:10
思路:大概手动算了一下sg的值,算到8的时候其实就知道了,当为7的倍数的时候sg值为8,为8的倍数时候sg值为7,然后其他的话都是sg(x)=x的,然后异或异或就可以了
#include<bits/stdc++.h>using namespace std;const int maxn= 1e6+7;#define LL long longint a[maxn];int main(){int T;scanf("%d",&T);while(T--){int n;LL sg = 0;scanf("%d",&n);for(int i = 1;i<=n;i++){LL temp;scanf("%lld",&temp);if(temp%8==0)temp--;else if(temp%8==7)temp++; sg^=temp;}if(sg==0)printf("Second player wins.\n");elseprintf("First player wins.\n");834078}}
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
0 0
- hdu5795 A Simple Nim(博弈找规律)
- 【HDU5795】 A Simple Nim(博弈)
- HDU 5795 A Simple Nim(博弈+找规律)
- HDU5795 A Simple Nim
- HDU5795 A Simple Nim
- A Simple Nim hdu5795
- HDU 5795 A Simple Nim (找规律+sg函数+博弈)
- HDU5795 A Simple Nim(SG函数)
- HDU5795-A Simple Nim(SG函数)
- HDU5795 A Simple Nim sg函数
- HDU-5795-A Simple Nim-博弈(SG函数)打表找规律
- HDU 5795 A Simple Nim 详解(SG打表找规律,博弈好题)
- HDU 5795 A Simple Nim(博弈)
- 【HDOJ5795】 A Simple Nim(博弈)
- 2016多校训练Contest6: 1003 A Simple Nim hdu5795
- Acdream 1416 Crazy Nim(简单博弈找规律)
- HDOJ1564Play a game(找规律博弈)
- HDU 2311-Nim or not Nim?(Nim博弈-打sg表找规律)
- Maximo 教程 (1)
- 【校内互测】Sunshine’s string(merge) (状压dp)
- MFC文件夹打开,文件打开,文件夹下文件遍历(转载)
- HDOJ 5025 Saving Tang Monk(BFS + 优先队列 + 状态压缩)
- CDOJ1328 卿学姐与诡异村庄
- hdu5795 A Simple Nim(博弈找规律)
- poj 2240 Arbitrage
- java与c++的主要区别
- 扩展欧几里德,求逆元模板
- Hdu 4594 Difference(奇圈判断+差分约束)
- 杂谈——美妙的信息奥赛集训班
- 顺时针打印矩阵
- C语言实现显示日历
- HDU 5795 A Simple Nim