Paint Chain

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

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个白色珠子染色,不能操作者输,问先手状态。

   先计算出线性状态下的游戏的sg函数,再计算与真实状态的sg函数时判断sg[n-m]=sg[n-m]==0?1:0。

由于子状态只有一种。

 #include<bits/stdc++.h>
using namespace std;
int sg[];
bool vis[];
int main(){
int t,n,m,i,j,k;
cin>>t;
for(int cas=;cas<=t;++cas){
cin>>n>>m;
printf("Case #%d: ",cas);
if(n<m){
puts("abcdxyzk");
continue;
}
for(i=;i<m;++i) sg[i]=;
for(i=m;i<=n;++i){
memset(vis,,sizeof(vis));
for(j=;j+m-<=i;j++){
vis[sg[j-]^sg[i-m-j+]]=;
}
for(j=;;j++){
if(!vis[j]){
sg[i]=j;
break;
}
}
}
for(i=;i<=n;++i){
if(sg[i]==) sg[i]=;
else sg[i]=;
}
sg[n-m]?puts("aekdycoin"):puts("abcdxyzk");
}
return ;
}

hdu-3980-nim博弈/sg函数的更多相关文章

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

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

  2. hdu 3032(博弈sg函数)

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

  3. hdu 3980 Paint Chain sg函数

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

  4. POJ 2311 Cutting Game(Nim博弈-sg函数/记忆化搜索)

    Cutting Game 题意: 有一张被分成 w*h 的格子的长方形纸张,两人轮流沿着格子的边界水平或垂直切割,将纸张分割成两部分.切割了n次之后就得到了n+1张纸,每次都可以选择切得的某一张纸再进 ...

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

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

  6. HDU 3032 Nim or not Nim? (sg函数)

    Nim or not Nim? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

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

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

  8. 尼姆博弈+SG函数

    博弈这个东西真的很费脑诶.. 尼姆博奕(Nim Game):游戏者轮流从一堆棋子(或者任何道具)中取走一个或者多个,最后不能再取的就是输家.当指定相应数量时,一堆这样的棋子称作一个尼姆堆 当n堆棋子的 ...

  9. HDU 2509 Nim博弈变形

    1.HDU 2509  2.题意:n堆苹果,两个人轮流,每次从一堆中取连续的多个,至少取一个,最后取光者败. 3.总结:Nim博弈的变形,还是不知道怎么分析,,,,看了大牛的博客. 传送门 首先给出结 ...

  10. HDU-4678 Mine 博弈SG函数

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

随机推荐

  1. C/C++之extern "C"的用法解析

    extern "C"的用法解析 http://blog.sina.com.cn/u/494a1ebc010004g5 C++中extern “C”含义深层探索 1.引言 C++语言 ...

  2. centos上安装python3.6

    安装python3.6可能使用的依赖 # yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sql ...

  3. python之路----模块调用

    如何使用模块? 1 import 示例文件:自定义模块my_module.py,文件名my_module.py,模块名my_module #my_module.py print('from the m ...

  4. 计算概论(A)/基础编程练习2(8题)/3:计算三角形面积

    #include<stdio.h> #include<math.h> int main() { // 声明三角形的三个顶点坐标和面积 float x1, y1, x2, y2, ...

  5. django admin 使用

    Django admin 中一些常用的设置 Django自带的后台管理是Django明显特色之一,可以让我们快速便捷管理数据.后台管理可以在各个app的admin.py文件中进行控制.以下是我最近摸索 ...

  6. 20145101《Java程序设计》第10周学习总结

    20145101<Java程序设计>第10周学习总结 教材学习内容总结 网络编程 网络编程的实质就是两个(或多个)设备(例如计算机)之间的数据传输. 计算机网络 路由器和交换机组成了核心的 ...

  7. 20145336张子扬《网络对抗》MSF基础应用

    20145336张子扬 <网络对抗>MSF基础应用 实验一:主动攻击,利用ms08_067漏洞进行攻击 首先使用use exploit/windows/smb/ ms08_067 _net ...

  8. 解决Navicat Premium 12 连接oracle数据库出现ORA-28547的问题

    1. 出现的问题... 下午工作时想连接Oracle数据库,使用的是Navicat Premium 12 . 数据库地址.用户名.密码.端口号都没有问题,但出现了ORA-28547:connectio ...

  9. Android学习笔记之 ActionBar

    http://developer.android.com/guide/topics/ui/actionbar.html 1,ActionBar的几种形式 2,使用ActionBar需要Activity ...

  10. Python3基础 __getattr__ 访问不存在的属性时,新增提示功能

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...