hdu 3980 Paint Chain (sg函数 )
来源:互联网 发布:淘宝买东西受骗怎么办 编辑:程序博客网 时间:2024/06/07 05:48
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
大致题意:首先输入一个样例数T表示有T组样例,接着有T行,每行输入两个数n和m,n表示一个项链上有n个珠子,m表示每次所要染色的连续的珠子的个数,Aekdycoin先染色,abcdxyzk后染,两人交替染色,谁先无法染色谁输,输出赢的人的名字。
思路:sg函数
代码如下
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>#include <string>#define LL long long intusing namespace std;const int maxn=1010;int sg[maxn];bool vis[maxn];int m;int mex(int n){ if(sg[n]!=-1) return sg[n]; if(n<m) return sg[n]=0; memset(vis,0,sizeof(vis)); for(int i=m;i<=n;i++) vis[mex(i-m)^mex(n-i)]=1; int i=0; while(vis[i]) { i++; } return sg[n]=i;}int main(){ int T; cin>>T; for(int i=1;i<=T;i++) { int n; cin>>n>>m; if(n<m) { printf("Case #%d: abcdxyzk\n", i); continue; } n-=m; memset(sg,-1,sizeof(sg)); for(int j=0;j<=n;j++) sg[j]=mex(j); if(sg[n]==0) printf("Case #%d: aekdycoin\n",i); else printf("Case #%d: abcdxyzk\n",i); } return 0;}
- HDU 3980 Paint Chain(SG函数)
- hdu 3980 Paint Chain (sg函数 )
- hdu 3980 Paint Chain(SG函数)
- HDU 3980 Paint Chain(博弈论,SG函数)
- HDU 3980 Paint Chain(博弈 SG)
- HDOJ 3980 Paint Chain 博弈 SG函数
- hdu3980 Paint Chain SG函数
- HDU3980 Paint Chain SG函数
- HDU 3980 Paint Chain(SG环链游戏)
- HDU 3980 Paint Chain
- hdu 3980 Paint Chain
- (HDU 3980)Paint Chain (Nim博弈,环变链)
- HDU 3980 Paint Chain(尼姆博弈)
- hdu 3980. Paint Chain
- Hdu 2980Paint Chain(博弈论)
- hdoj 3980 Paint Chain(数学推导)
- HDU 1848(SG函数应用)
- hdu 1536 博弈 SG函数(dfs)
- day55_电力项目_lucene在检索中的应用
- 3. Longest Substring Without Repeating Characters
- 183. Customers Who Never Order
- (转载)JAVA设计模式之工厂模式(简单工厂模式+工厂方法模式)
- hdu1242(Rescue)深搜
- hdu 3980 Paint Chain (sg函数 )
- Spring boot data JPA数据库映射关系 : @OneToOne,@OneToMany,@ManyToMany
- Java —— MessageFormat类 处理国际化
- PDFrenderer
- SO_REUSEADDR套接字选项
- 有一个二维数组. 数组的每行从左到右是递增的,每列从上到下是递增的. 在这样的数组中查找一个数字是否存在。 时间复杂度小于O(N)
- Android on the transplant ghostscript-9.04 static compiler
- 单例模式实现:枚举单例
- C Datastructure 5 ---- stack