Paint Chain

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

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

题意:有一圈 N 个的硬币, 两个玩家轮流取,每次他们可以取M个连续硬币, 最后一个不能取的为负;

#include<iostream>
#include<cstdio>
#include<cstring> using namespace std; const int N=; int n,m,sg[N]; int mex(int x){
if(sg[x]!=-)
return sg[x];
int re[N];
memset(re,,sizeof(re));
for(int i=;i<=x-m-i;i++)
re[mex(i)^mex(x-m-i)]=;
int i=;
while(re[i]!=)
i++;
return sg[x]=i;
} int main(){ //freopen("input.txt","r",stdin); int t,cases=;
scanf("%d",&t);
while(t--){
memset(sg,-,sizeof(sg));
printf("Case #%d: ",++cases);
scanf("%d%d",&n,&m);
if(n<m){
puts("abcdxyzk");
continue;
}
if(m==){
if(n&)
puts("aekdycoin");
else
puts("abcdxyzk");
continue;
}
if(!mex(n-m))
puts("aekdycoin");
else
puts("abcdxyzk");
}
return ;
}

HDU 3980 Paint Chain (sg函数)的更多相关文章

  1. hdu 3980 Paint Chain sg函数

    题目链接 给一个长度为n的环, 两个人轮流涂色, 每次涂m个连续的, 无法继续涂了就输. #include<bits/stdc++.h> using namespace std; #def ...

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

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

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

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

  4. HDU 3970 Paint Chain (博弈,SG函数)

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

  5. HDU 5724 Chess(SG函数+状态压缩)

    http://acm.split.hdu.edu.cn/showproblem.php?pid=5724 题意: 现在有一个n*20的棋盘,上面有一些棋子,双方每次可以选择一个棋子把它移动到其右边第一 ...

  6. hdu 3032(博弈sg函数)

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

  7. hdu 1079 Calendar Game sg函数 难度:0

    Calendar Game Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  8. HDU 5724 Chess(SG函数)

    Chess Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submi ...

  9. HDU 1535 S-Nim(SG函数)

    S-Nim Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

随机推荐

  1. AVR单片机最小系统 基本硬件线路与分析

    单片机最小系统  单片机最小系统设计 AVR基本硬件线路设计与分析 (ATmega16功能小板) AVR DB-CORE Ver2.3 Atmega16开发板 本站商城提供本最小系统销售:99元 AV ...

  2. Android 7.1.1 之实现 3D Touch

    转载请注明出处:http://blog.csdn.net/yyh352091626/article/details/68962736 Shortcut概念 详细实现 BuildConfig 配置 静态 ...

  3. 性能测试工具——Mxdperfstat

    Mxdperfstat是一款mxd性能检测工具,使用它来测试专题地图的性能非常不错! 获取工具 https://www.arcgis.com/home/item.html?id=a269d03aa1c ...

  4. C/S通信模型与B/S通信模型介绍

    1.客户端与服务器之间的通信模型 基于Socket连接的客户端与服务器之间的通信模型图如上图所示,整个通信过程如下所示: (1) 服务器端首先启动监听程序,对指定的端口进行监听,等待接收客户端的连接请 ...

  5. ZH奶酪:Ubuntu 14.04配置LAMP(Linux、Apache、MySQL、PHP)

    ZH奶酪:Ubuntu 14.04安装LAMP(Linux,Apache,MySQL,PHP) 之前已经介绍过LAMP的安装,这边文章主要讲解一下LAMP的配置. 1.配置Apache (1)调整Ke ...

  6. 使用树莓派3获取CPU温度

    一.命令: cat /sys/class/thermal/thermal_zone0/temp 二.上图:

  7. Postgresql中的数据类型大全

    一.数值类型: 下面是PostgreSQL所支持的数值类型的列表和简单说明: 名字 存储空间 描述 范围 smallint 2 字节 小范围整数 -32768 到 +32767 integer 4 字 ...

  8. excel自定义数据验证

    1. 判断必须为5位或者9位的数字 2. 自定义限制级别和提示消息

  9. 《鸟哥的Linux私房菜》学习笔记0——计算机概论

    一:CPU架构 精简指令集CPU:SPARC系列.PowerPC系列.ARM系列.其中,ARM CPU广泛应用于手机.PDA.导航系统等设备. 复杂指令集CPU:x86架构的CPU,大量用于个人电脑, ...

  10. 腾讯云ubuntu安装Mysql并配置远程访问

    转载请注明原文地址:http://www.cnblogs.com/ygj0930/p/6378914.html 一:修改SSH配置 输入 su 进入root模式.修改ssh配置: sudo vi /e ...