hdu3980Paint Chain+SG博弈
来源:互联网 发布:org.apache jar包 编辑:程序博客网 时间:2024/06/07 09:17
Problem Description
Aekdycoin and abcdxyzk are playing a game. They get a circle chain with some beads. Initially none of the beads is painted. They take turns to paint the chain. In Each turn one player must paint a unpainted beads. Whoever is unable to paint in his turn lose the game. Aekdycoin will take the first move.
Now, they thought this game is too simple, and they want to change some rules. In each turn one player must select a certain number of consecutive unpainted beads to paint. The other rules is The same as the original. Who will win under the rules ?You may assume that both of them are so clever.
Input
First line contains T, the number of test cases. Following T line contain 2 integer N, M, indicate the chain has N beads, and each turn one player must paint M consecutive beads. (1 <= N, M <= 1000)
Output
For each case, print “Case #idx: ” first where idx is the case number start from 1, and the name of the winner.
Sample Input
2
3 1
4 2
Sample Output
Case #1: aekdycoin
Case #2: abcdxyzk
Author
jayi
Source
2011 Multi-University Training Contest 14 - Host by FZU
一个圆环N个数,每次每个人只能给连续的M个数抹漆,最后不能抹的就算输(大概这个意思啦,英语不好)。。首先第一个人抹了之后就变成直线了。。先手变后手了..
(5,2) +++++之后的状态可以有<–+++><+–++><++–+><+++–>
一个问题的结果是其子问题的结果的亦或。。。
对于一个直线的情况,其子状态有前边空几个那么多的情况。。
比如(5,2) +++++,
当前边空0个时子游戏为(0,2)(3,2)
当前边空1个时子游戏有(1,2)(2,2)
当前边空2个时子游戏有(2,2)(1,2)
当前边空3个时子游戏有(3,2)(0,2)
所以求SG时记忆化递推。。就可以求出(n,m)状态的SG。
好了贴代码。。
#include<cstdio>#include<cmath>#include<cstring>#include<iostream>#include<algorithm>#include<cstdlib>#include<queue>#include<vector>#include<map>#include<stack>#include<set>using namespace std;typedef long long LL;int SG[1005];int getSG(int n,int m){ if(n<m) return SG[n]=0; if(SG[n]!=-1) return SG[n]; bool visit[1005];// //下边递归了。。不要放全局去。。。 memset(visit,false,sizeof(visit)); for(int i=0;i<=n-m;i++){ visit[getSG(i,m)^getSG(n-m-i,m)]=true; } for(int i=0;;i++){ if(visit[i]==false){ SG[n]=i; break; } } return SG[n];}int main(){ int t; scanf("%d",&t); for(int test=1;test<=t;test++){ int n,m; scanf("%d %d",&n,&m); memset(SG,-1,sizeof(SG)); printf("Case #%d: ",test); if(n<m||getSG(n-m,m)) printf("abcdxyzk\n"); else printf("aekdycoin\n"); } return 0;}/*23 1*/
- hdu3980Paint Chain+SG博弈
- hdu3980Paint Chain(SG)
- HDU3980Paint Chain(尼姆博奕SG)
- HDOJ 3980 Paint Chain 博弈 SG函数
- HDU 3980 Paint Chain(博弈 SG)
- HDU1851(sg博弈+nim博弈)
- 博弈,求SG值
- poj2960【Nim博弈,SG】
- 博弈 nim sg
- HDOJ1404(SG博弈)
- HDOJ1792(SG博弈)
- HDU 1536 (博弈SG)
- SG函数 博弈
- hdu1907||poj3480 sg博弈
- hdu 2509 sg博弈
- hdu 1729 sg博弈
- 博弈,求sg值
- zoj 3529 博弈SG
- 求解单源最短路径:Dijkstara算法典型示例
- Spark Transformation —— subtract
- UVA 11609 Teams
- HDU2899
- poj2060Taxi Cab Scheme(最小路径覆盖)
- hdu3980Paint Chain+SG博弈
- 机房收费系统总结
- MVP的工作原理
- Java设计模式-单例模式
- 找点题做(hdu分类)
- cocos2dx源码阅读之万能的Value
- SQL四中连接(左外连接、右外连接、内连接、全连接)
- hdu 1006
- 手机震动