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. Arrow functions and the ‘this’ keyword

    原文:https://medium.freecodecamp.org/learn-es6-the-dope-way-part-ii-arrow-functions-and-the-this-keywo ...

  2. Is there anyway to discover which ip addresses are connected to the db?

    From mongo shell run db.currentOp() to show all active connections or db.currentOp(true) to show all ...

  3. VC++导出具有命名空间的函数

    问题现象 原因分析 解决的方法 1 问题现象 导出具有命名空间的函数和类.源码例如以下: 头文件MiniMFC.h namespace MiniMFC { __declspec(dllexport) ...

  4. FastDFS tracker storage 的工作原理及流程

    FastDFS tracker storage 的工作原理及流程 2013 年 3 月 11 日 – 09:22 | 1,409 views | 收藏  (No Ratings Yet) FastDF ...

  5. 一次性解决Intellij IDEA maven 自动跳到1.5的JDK

    说明:文章学习自:https://blog.csdn.net/Zereao/article/details/77427989 一.找到Setting.xml文件 打开setting.xml 说明,该文 ...

  6. Spring的PropertyPlaceholderConfigurer事例应用

    在开发的过程中,经常发现一些类似:${log4j.level}之类的内容,后来才知道原因.下面解释一下: 1.PropertyPlaceholderConfigurer是个bean工厂后置处理器的实现 ...

  7. sublime text执行PHP代码

    新建编译系统 { "cmd": ["php", "$file"], "file_regex": "php$&q ...

  8. linux CPU占用率高(转)

    来自:http://www.cnitblog.com/houcy/archive/2012/11/28/86801.html 1.用top命令查看哪个进程占用CPU高 gateway网关进程14094 ...

  9. 使用Gulp

    为什么要使用Gulp 在前端开发中通常须要做,预处理语言的编译.js文件的压缩.css文件的压缩.图片的压缩等一系列工作,而使用Gulp能够自己主动化的完毕这些工作,从而提高站点的开发效率,在我的博客 ...

  10. unique-paths I &II 路径数,动态规划

    A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The ...