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. Js基础知识2-对象、对象属性全解

    Object对象 Object对象包含如下属性和方法,也就意味着一切对象(函数也是对象)都包含如下方法. 每种方法和属性在不同的对象中有不同的作用,并不是每种对象都有使用每个方法的必要. 下面是Obj ...

  2. JS方法的使用

    $("#yingxiang_id li").each(function () { if ($(this).find(".div-relative").attr( ...

  3. web前端----jQuery基础语法

    一.jQuery基础1.为什么要用jquery? 写起来简单,省事,开发效率高,兼容性好2.什么是jQuery? jQuery是一个兼容多浏览器的JavaScript库(类似python里面的模块)3 ...

  4. 计算概论(A)/基础编程练习2(8题)/4:骑车与走路

    #include<stdio.h> int main() { // 待处理的数据数量n ; scanf("%d", &n); float meters[n]; ...

  5. (二) MySQL常用命令及语法规范

  6. mongodb 最佳可视化工具mongobooster

    最好用的mongodb GUI工具 mongobooster,没有之一,可从https://mongobooster.com/下载 常见管理命令可参考,http://www.cnblogs.com/l ...

  7. 20145306 网路攻防 web安全基础实践

    20145306 网络攻防 web安全基础实践 实验内容 使用webgoat进行XSS攻击.CSRF攻击.SQL注入 XSS攻击:Stored XSS Attacks.Reflected XSS At ...

  8. Android 手机小闹钟

    Android 手机小闹钟 一.这一篇主要使用系统为我们提供的一个服务AlarmManager来制作一个Android小闹钟,同时还涉及到了自定义主题.判断第一次启动应用.自定义动画.对话框.制作关闭 ...

  9. 20165310 java_blog_week4

    2165310 <Java程序设计>第4周学习总结 教材学习内容总结 继承(extends) 同一个包内:继承除了private修饰的变量与方法 不同包内:不继承private和友好,继承 ...

  10. Python3基础 getatime getctime getmtime 文件的最近访问 + 属性修改 + 内容修改时间

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