Paint Chain

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 909    Accepted Submission(s): 325

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

用SG函数搞一遍就可以了。

 /* ***********************************************
Author :kuangbin
Created Time :2013-11-17 19:20:19
File Name :E:\2013ACM\比赛练习\2013-11-17\H.cpp
************************************************ */ #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
const int MAXN = ;
int sg[MAXN];
bool vis[MAXN];
int m;
int mex(int n)
{
if(sg[n] != -)return sg[n];
if(n < m)return sg[n] = ;
memset(vis,false,sizeof(vis));
for(int i = m;i <= n;i++)
vis[mex(i-m)^mex(n-i)] = true;
for(int i = ;;i++)
if(vis[i] == false)
{
sg[n] = i;
break;
}
return sg[n];
} int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int T;
int n;
scanf("%d",&T);
int iCase = ;
while(T--)
{
scanf("%d%d",&n,&m);
iCase++;
if(n < m)
{
printf("Case #%d: abcdxyzk\n",iCase);
continue;
}
n -= m;
memset(sg,-,sizeof(sg));
for(int i = ;i <= n;i++)
sg[i] = mex(i);
if(sg[n] == )printf("Case #%d: aekdycoin\n",iCase);
else printf("Case #%d: abcdxyzk\n",iCase);
}
return ;
}

HDU 3970 Paint Chain (博弈,SG函数)的更多相关文章

  1. HDU 3980 Paint Chain (sg函数)

    Paint Chain Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  2. HDU - 3980 Paint Chain(SG函数)

    https://vjudge.net/problem/HDU-3980 题意 一串长度为n的柱子,每个人只能给连续的珠子涂色,涂过的不能再涂,不能涂的人就输了,问最后谁获胜. 分析 第一个人先涂m个, ...

  3. S-Nim HDU 1536 博弈 sg函数

    S-Nim HDU 1536 博弈 sg函数 题意 首先输入K,表示一个集合的大小,之后输入集合,表示对于这对石子只能去这个集合中的元素的个数,之后输入 一个m表示接下来对于这个集合要进行m次询问,之 ...

  4. hdu 3980 Paint Chain 组合游戏 SG函数

    题目链接 题意 有一个\(n\)个珠子的环,两人轮流给环上的珠子涂色.规定每次涂色必须涂连续的\(m\)颗珠子,无法继续操作的人输.问先手能否赢. 思路 参考 转化 第一个人取完之后就变成了一条链,现 ...

  5. hdu 3032(博弈sg函数)

    题意:与原来基本的尼姆博弈不同的是,可以将一堆石子分成两堆石子也算一步操作,其它的都是一样的. 分析:由于石子的堆数和每一堆石子的数量都很大,所以肯定不能用搜索去求sg函数,现在我们只能通过找规律的办 ...

  6. HDU 1848 Fibonacci again and again (斐波那契博弈SG函数)

    Fibonacci again and again Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & ...

  7. hdu 5795 A Simple Nim 博弈sg函数

    A Simple Nim Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Pro ...

  8. HDU-4678 Mine 博弈SG函数

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4678 题意就不说了,太长了... 这个应该算简单博弈吧.先求联通分量,把空白区域边上的数字个数全部求出 ...

  9. hdu-3980-nim博弈/sg函数

    Paint Chain Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

随机推荐

  1. Spring Mvc + Maven + yuicompressor 使用 profile 来压缩 javascript ,css 文件; (十)

    profile相关知识点: 在开发项目时,设想有以下场景: 你的Maven项目存放在一个远程代码库中(比如github),该项目需要访问数据库,你有两台电脑,一台是Linux,一台是Mac OS X, ...

  2. [python]小技巧集锦

    1.数组过滤,只适用于numpy alpha[alpha>0]:返回alpha中大于0的元素组成的数组 2.在范围内选取不等于某值的数值 j = i while j==i: j = int(ra ...

  3. Javascript Jquery 中的数组定义与操作

    1.认识数组 数组就是某类数据的集合,数据类型可以是整型.字符串.甚至是对象Javascript不支持多维数组,但是因为数组里面可以包含对象(数组也是一个对象),所以数组可以通过相互嵌套实现类似多维数 ...

  4. 蓝桥杯 问题 1117: K-进制数 (递归)

    题目链接 题目描述 考虑包含N位数字的K-进制数. 定义一个数有效, 如果其K-进制表示不包含两连续的0. 考虑包含N位数字的K-进制数. 定义一个数有效, 如果其K-进制表示不包含两连续的0. 例: ...

  5. 洛谷 P1006 传纸条 多维DP

    传纸条详解: 蒟蒻最近接到了练习DP的通知,于是跑来试炼场看看:发现有点难(毕竟是蒟蒻吗)便去翻了翻题解,可怎么都看不懂.为什么呢?蒟蒻发现题解里都非常详细的讲了转移方程,讲了降维优化,但这题新颖之处 ...

  6. Mybatis逆向工程——(十四)

    逆向工程可以快速将数据库的表生成JavaBean,同时生成对单标操作的Mapper.java与Mapper.xml,极大地提高了开发速度. 1.jar包

  7. 在 Ubuntu13.10 服务器中安装 Munin(监视工具)【转】

    Munin 监测工具可检测所有的计算机,并记录好看到的计算机.通过图形Web界面的的方式显示所有信息.重点是即插即用的功能.完成安装后,大量的控插件会被打. 使用 Munin 您可以轻松地监视您的计算 ...

  8. webRTC视频通话,https协议,录制端和播放端

    最近做视频直播模块,在网上也看到很多大神写的代码,写的都不错,但不是我想要的,有的可能比较老,不支持https协议,有的又将直播端和显示端放在一个程序中,不利于我使用,则本篇着重添加了https协议( ...

  9. javaweb笔记三

    //写了注解,就不用在web.xml里进行注册@WebServlet(urlPatterns="/my",name="my",loadOnStartup=1,i ...

  10. unit测试出现异常:Exception in thread "main" java.lang.NoSuchMethodError: org.junit.platform.commons.util

    在进行单元测试时,测试出现异常 Exception in thread "main" java.lang.NoSuchMethodError: org.junit.platform ...