HDU 3980 Paint Chain(博弈 SG)
来源:互联网 发布:安卓扫雷源码 编辑:程序博客网 时间:2024/06/05 02:40
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3980
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.
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
PS:http://blog.csdn.net/zhjchengfeng5/article/details/8214768
题意
两个人在一个由 n 个玻璃珠组成的一个圆环上玩涂色游戏,游戏的规则是:
1、每人一轮,每轮选择一个长度为 m 的连续的、没有涂过色的玻璃珠串涂色
1、每人一轮,每轮选择一个长度为 m 的连续的、没有涂过色的玻璃珠串涂色
2、不能涂色的那个人输掉游戏
做法分析
可以肯定的是,第一个人涂色之后就把环变成了一个长度为 n-m 的链了,那么我们就可以这样划分阶段了:每轮从一些线段中选择一个,并且把那条线段分成 x, m, len-x-m 的三个部分,其中 len 表示线段原来的长度,m 表示的是已经涂色了,那么这个长为 len 的线段能够得到的子状态最多有 len-m+1 个(其实由对称性可知实际的状态数只是这里的一半),变成了两个长度为 x 和 len-x-m 子游戏,由 SG 定理,SG(len)=SG(x)^SG(len-x-m) 而再由 SG 函数的定义式 SG[u]=mex(seg[v]) 其中,状态 u 可以直接得到状态 v,再加上一个记忆化的小优化,AC了。。。
代码如下:
#include <cstdio>#include <cstring>int SG[1056];int vis[1056];int n, m;int get_SG(){ memset(SG,0,sizeof(SG)); SG[m] = 1; for(int i = m+1; i <= n; i++)//get Sprague-Grundy value; { memset(vis,0,sizeof(vis)); for(int j = 0; j < i-m; j++) { vis[SG[j]^SG[i-m-j]] = 1; } for(int j = 0; ; j++)//求mex{}中未出现的最小的非负整数 { if(!vis[j]) { SG[i] = j; break; } } } return SG[n-m];}int main (){ int t; int cas = 0; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); printf("Case #%d: ",++cas); if(get_SG() || n < m) printf("abcdxyzk\n"); else printf("aekdycoin\n"); } return 0;}
1 0
- 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函数
- HDU 3980 Paint Chain(博弈论,SG函数)
- (HDU 3980)Paint Chain (Nim博弈,环变链)
- HDU 3980 Paint Chain(尼姆博弈)
- HDU 3980 Paint Chain(SG环链游戏)
- HDU 3980 Paint Chain
- hdu 3980 Paint Chain
- hdu3980Paint Chain+SG博弈
- hdu3980 Paint Chain SG函数
- HDU3980 Paint Chain SG函数
- hdu 1079 (SG博弈)
- hdu 3980. Paint Chain
- poj2960(hdu也有,SG博弈)
- hdu 4678 Mine(SG博弈)
- 编写一个自定义的String类
- LeetCode-Merge Two Sorted Lists
- HTML5设计原则
- apache几种工作模式对比
- Leetcode: Largest Number
- HDU 3980 Paint Chain(博弈 SG)
- 【机器学习】机器学习(一)——基于概率论的分类
- iOS开发-ARC下weak strong使用
- Cannot assign to 'self' outside of a method in the init family
- LeetCode 17.Letter Combinations of a Phone Number
- 上楼梯问题
- Projections常用的聚合查询方法介绍
- burpsuit安装及使用教程
- 构造函数和析构函数是否可以被重载