HDU 5795 A Simple Nim
来源:互联网 发布:小学测验软件 编辑:程序博客网 时间:2024/05/12 20:04
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5795
题意:一个n堆的取石子游戏,每次可以取一堆中的任意个,或者将当前堆分为三个非空堆。求先手/后手必胜。
思路:打表sg函数找规律。hihocoder上面有类似的题目,不过那个是分为两堆。
http://hihocoder.com/problemset/problem/1173
#include <cstdio>#include <cmath>#include <cstring>#include <string>#include <cstdlib>#include <iostream>#include <algorithm>#include <stack>#include <map>#include <set>#include <vector>#include <sstream>#include <queue>#include <utility>using namespace std;#define rep(i,j,k) for (int i=j;i<=k;i++)#define Rrep(i,j,k) for (int i=j;i>=k;i--)#define Clean(x,y) memset(x,y,sizeof(x))#define LL long long#define ULL unsigned long long#define inf 0x7fffffff#define mod 100000007//int sg[1009];////void init()//{// sg[0] = 0;// bool f[1009];// rep(i,1,100)// {// Clean(f,false);// rep(j,1,i)// f[ sg[i-j] ] = true;// if ( i >= 3 )// {// rep(j,1,i-2)// rep(k,1,i-2)// if ( j+k < i )// f[ sg[j] ^ sg[k] ^ sg[i-j-k] ] = true;// }// int j = 0;// while ( f[j] ) j++;// sg[i] = j;// cout<<i<<" : "<<sg[i]<<endl;// }//}int main(){ //init(); int T,n,temp; cin>>T; while(T--) { int ans = 0; scanf("%d",&n); rep(i,1,n) { scanf("%d",&temp); if ( temp % 8 == 0 ) ans ^= temp-1; else if ( temp % 8 == 7 ) ans ^= temp + 1; else ans ^= temp; } puts( ans ? "First player wins." : "Second player wins." ); } return 0;}
0 0
- hdu 5795 A Simple Nim
- HDU 5795 A Simple Nim
- HDU 5795 A Simple Nim
- hdu 5795 A Simple Nim
- hdu 5795 A Simple Nim
- HDU 5795 A simple Nim [SG]【博弈】
- HDU 5795 A Simple Nim(博弈)
- hdu 5795 A Simple Nim (sg函数)
- HDU 5795 A Simple Nim【博弈】
- HDU 5795 A Simple Nim(SG打表找规律)
- hdu 5795A Simple Nim SG函数(多校)
- HDU 5795 A Simple Nim (打表找规律)
- HDU 5795 A Simple Nim (找规律+sg函数+博弈)
- HDU 5795 A Simple Nim(博弈+找规律)
- 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 4594 Difference(奇圈判断+差分约束)
- 杂谈——美妙的信息奥赛集训班
- 顺时针打印矩阵
- C语言实现显示日历
- HDU 5795 A Simple Nim
- Oracle OAF嵌入ADF界面方法
- Java抽象类和接口
- HDOJ-----1598并查集
- 哈夫曼树及其算法实现
- HDU 5627 Clarke and MST(贪心)
- iOS --webView简单使用(一)
- 计算几何初步
- React Native开发安装和创建工程