HDU 2999 Stone Game, Why are you always there? (构造 SG函数)
来源:互联网 发布:php源码 月卡验证 编辑:程序博客网 时间:2024/05/18 02:04
转载请注明出处,谢谢 http://blog.csdn.net/ACM_cxlove?viewmode=contents by---cxlove
题目:给出一串石头,和一个集合,每次取出若干个连续的石头(数量必须为集合中的),最后取完的获胜,问有没有必胜策略。
http://acm.hdu.edu.cn/showproblem.php?pid=2999
好像不是很理解SG函数的含义, 可还是乱七八糟的搞出了SG,然后水过去。
对于一个连续的串,比如说长度为5,可行只有2,那么取了之后可能分为两段
如后继可能为:(1,3),{(1),(4,5)},{(1,2),(5)},{3,5}这四种情况。两个区间异或之后,取mex操作
虽不明但觉厉,然后就AC了。
局面是确定的,没有存在不确定的情况
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#define N 10005#define LL long long#define inf 1<<29#define eps 1e-7using namespace std;int n,a[100],m,k,cnt,sg[1005];int get_sg(int n){if(sg[n]!=-1)return sg[n];int vis[10000];memset(vis,0,sizeof(vis));for(int i=0;i<cnt&&a[i]<=n;i++){for(int j=0;j<=(n-a[i]);j++){if(sg[j]==-1) sg[j]=get_sg(j); if(sg[n-j-a[i]]==-1) sg[n-j-a[i]]=get_sg(n-j-a[i]);vis[sg[j]^sg[n-j-a[i]]]=1;}}for(int i=0;;i++)if(vis[i]==0)return i;}int main(){while(scanf("%d",&n)!=EOF){for(int i=0;i<n;i++)scanf("%d",&a[i]);sort(a,a+n);cnt=1;for(int i=1;i<n;i++)if(a[i]!=a[cnt-1])a[cnt++]=a[i];int q;scanf("%d",&q);memset(sg,-1,sizeof(sg));while(q--){scanf("%d",&k);if(sg[k]==-1)sg[k]=get_sg(k);if(sg[k])puts("1");elseputs("2");}}return 0;}
- HDU 2999 Stone Game, Why are you always there? (构造 SG函数)
- Stone Game, Why are you always there? - HDU 2999 sg函数
- HDOJ 2999 Stone Game, Why are you always there? 博弈 SG函数
- HDOJ 2999 Stone Game, Why are you always there? 博弈 SG函数
- HDU 2999 Stone Game, Why are you always there?
- hdu 2999 Stone Game, Why are you always there?
- hdu2999 Stone Game, Why are you always there?---sg 一排石子分成若干堆
- hdu2999 Stone Game, Why are you always there?
- hdu2999 Stone Game, Why are you always there? 组合NIM
- hdu2999Stone Game, Why are you always there?
- hdu Stone Game SG函数
- Why are you always smiling?
- HDU 1729 Stone Game (SG函数)
- HDU 1729 Stone Game 【博弈论,SG函数】
- hdu 1729 Stone Game(SG函数)
- sg函数 hdu 1729 Stone Game
- HDU 1729 Stone Game (sg函数)
- HDU 1729 Stone Game(SG函数)
- POJ 1002(字符串处理)
- git 忽略跟踪工程文件
- 有关指针
- myeclipse优化
- void assert (int expression)
- HDU 2999 Stone Game, Why are you always there? (构造 SG函数)
- Eclipse 中 工程 引用 其他 工程的 配置方法。
- android listview实现快速查询A—Z (模拟一些天气搜狐,网易等天气预报)
- java数据结构学习(一)
- 高精度求幂运算
- wxWidgets用平台相关的命令打开文件,执行命令
- 时间倒记时
- JAVA 获取上月最后一天
- 【python学习】之五、可调用对象