【博弈+SG函数+打表找规律】HDU_5795_A Simple Nim
来源:互联网 发布:it luggage 编辑:程序博客网 时间:2024/06/05 06:44
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.
224 431 2 4
Second player wins.First player wins.
#include <bits/stdc++.h>using namespace std;int vis[10010],sg[10010];/*//打表找规律int cal(int x){ memset(vis,0,sizeof(vis)); for(int i=0;i<x;i++)//x能到达0到x-1所有的状态 vis[sg[i]]=1; for(int i=1;i<x;i++){//分为3堆 for(int j=1;j<x&&i+j<x;j++){ for(int k=1;k<x&&i+j+k<=x;k++){ if(i+j+k==x) vis[sg[i]^sg[j]^sg[k]]=1; } } } for(int i=0;;i++)//mex(0,1,...x-1,分成三堆的sg值) if(!vis[i]) return sg[x]=i;}*/int cal(int x){ if(x%8==7) return x+1; else if(x%8==0) return x-1; return x;}int main(){ int t,n,x; scanf("%d",&t); while(t--){ int ans=0; scanf("%d",&n); for(int i=0;i<n;i++){ scanf("%d",&x); ans^=cal(x); } if(!ans) puts("Second player wins.");//异或值为0,必败状态 else puts("First player wins."); } /* memset(sg,-1,sizeof(sg)); sg[0]=0;sg[1]=1;sg[2]=2; for(int i=3;i<=100;i++){ printf("%d %d\n",i,cal(i)); }*/ return 0;}
阅读全文
0 0
- 【博弈+SG函数+打表找规律】HDU_5795_A Simple Nim
- hdu5795A 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打表找规律,博弈好题)
- HDOJ 5795 A Simple Nim (博弈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/hihoCoder1173+SG博弈
- 【Nim博弈与SG函数】
- Nim博弈与SG函数
- sg函数+nim博弈+打表_______A Simple Nim(hdu 5795 2016多校第六场)
- HDU 5795 A Simple Nim(Nim游戏博弈+SG函数)
- 378. Kth Smallest Element in a Sorted Matrix
- 小程序与html5开发的差别(连载三)
- H5面试题---介绍js的基本数据类型
- 有趣的if语句
- 使用CXF框架开发一个简单的WebService
- 【博弈+SG函数+打表找规律】HDU_5795_A Simple Nim
- JavaScript学习之简单的放大镜
- Android中View的宽高测量结果为0的原因和解决方法
- 阵列,配额与LVM
- &&重载实现寻找子集
- 【《Real-Time Rendering 3rd》 提炼总结】(六) 第七章 · 高级着色:BRDF及相关技术
- 文件流FileOutputStream类
- H5---js有哪些内置对象
- 动手实现并开源IDEOnline——代码高亮【富文本编辑框】