hdu 5708 Alice and Bob(尼姆博弈)
题目链接:hdu 5708
Alice and Bob
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65536 K (Java/Others)
Problem Description
Alice and Bob are playing a stone game in a board of n×m cells.
In the begining, the stone is in the upperleft cell. And in each turn, they can move the stone one cell to the right or one cell down, or diagonally k cells down to the right, which means if you are at (x,y), then you could move into (x+1,y), (x,y+1) or (x+k,y+k) at the next step. The player who can not move loses. They play in turns and Alice moves first.
Now given n, m and k, could you tell me who is the winner?
Input
First line contains an integer T(1≤T≤10), denoting the number of test cases.
In each test case, the first line is two integers Q and k.
In the following Q lines, each line contains n and m.(1≤Q≤1000,1≤k,n,m≤109)
Output
For each test case, output Q lines.
If Alice is the winner, output “Alice”. Otherwise “Bob”.
Sample Input
2
2 1
4 5
3 4
2 3
4 5
5 6
Sample Output
Alice
Alice
Alice
Bob
翻以前的比赛翻到这道题,之前女生赛期间对这道题根本无从下手,现在一看觉得可以做,于是画起了表,不过果然光凭画表还是比较难找规律,最后还是代码打表才找出了规律。
PS:这题过的人不多,是不会的人不会做,会的都懒得做嘛Orz。
以防万一说一下:如果有人不知道sg函数是啥就过来看这篇博客的话,你肯定连打表代码都看不懂,快去搜下sg函数和尼姆博弈。不过搜完看完,这道题基本就会了=。=
WA了一下,发现k = 1的时候还要特判一下Orz。
打表码:
#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <queue>
#include <algorithm>
#define M 21
#define mod 1000000007
#define INF -0x3f3f3f3fusing namespace std;int g[M][M];void sg(int k)
{for(int i = 2; i <= M; i += 2){g[i + 1][1] = g[1][i + 1] = 0;g[i][1] = g[1][i] = 1;}for(int i = 2; i <= M; i++){for(int j = 2; j <= M; j++){if((!g[i - 1][j]) || (!g[i][j - 1]) || ((!g[i - k][j - k]) && (i - k > 0) && (j - k > 0))){g[i][j] = 1;continue;}else{g[i][j] = 0;}}}
}int main()
{int T;scanf("%d", &T);while(T--){int k;scanf("%d", &k);sg(k);for(int j = 1; j <= M; j++){for(int k = 1; k <= M; k++){printf("%d ", g[j][k]);}printf("\n");}printf("\n\n\n\n");return 0;
}
ac码:
#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <queue>
#include <algorithm>
#define M 21
#define mod 1000000007
#define INF -0x3f3f3f3fusing namespace std;int main()
{int T;scanf("%d", &T);while(T--){int q, k;scanf("%d %d", &q, &k);while(q--){int n, m, t;scanf("%d %d", &n, &m);if(n < m)//由于表是关于主对角线对称的,为了判断方便让m保持是n和m中比较小的那个值。{t = n;n = m;m = t;}if(k == 1){if(m % 2){if((n - m) % 2)printf("Alice\n");elseprintf("Bob\n");}else{printf("Alice\n");}}else{t = 2 * (k + 1);//循环周期if((m % t >= 1) && (m % t <= k)){if((n - m) % 2)printf("Alice\n");elseprintf("Bob\n");}else if(!(m % (k + 1)))printf("Alice\n");else{if((n - m) % 2)printf("Bob\n");elseprintf("Alice\n");}}}}return 0;
}
hdu 5708 Alice and Bob(尼姆博弈)相关推荐
- hdu 1907 Jone 尼姆博弈
题目:点击打开链接 John Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) T ...
- HDU - 1907 John(尼姆博弈变形)
题目链接:点击查看 题目大意:给出 n 堆石子,两个人轮流取,至少取一个,取到最后一个的人输 题目分析:尼姆博弈是取到最后一个的人获胜,这个题正好反着 一个很显然的奇异局势就是,每一堆的石子的个数都为 ...
- hdu 1850 Being a Good Boy in Spring Festival (尼姆博弈)
Being a Good Boy in Spring Festival Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32 ...
- ZOJ 3964Yet Another Game of Stones 扩展尼姆博弈
ZOJ 3964Yet Another Game of Stones 扩展尼姆博弈 题意 思路 Code 传送门: 题意 给n堆石头,每堆石头有a个数量和b性质.Alice和Bob玩游戏,每次只能在一 ...
- 博弈论基础知识: 巴什博奕+斐波那契博弈+威佐夫博奕+尼姆博弈(及Staircase)
博弈论基础知识: 巴什博奕+斐波那契博弈+威佐夫博奕+尼姆博弈(及Staircase) 转载自: http://tieba.baidu.com/p/1474319443 http://blog.sin ...
- 博弈论学习之巴什博弈,尼姆博弈, sg博弈
博弈论真是一个神奇的东西,感觉和博弈论厉害的人玩游戏绝对会输. 这个博客讲的很好很全面 此类问题一般有如下特点: 1.博弈模型为两人轮流决策的非合作博弈.即两人轮流进行决策,并且两人都使用最优策略来获 ...
- 博弈论总结 必胜点 SG函数 巴什博弈 尼姆博弈
摘要 主要算法思想,应用领域,近年来的出题情况 博弈是信息学和数学试题中常会出现的一种类型,算法灵活多变是其最大特点,而其中有一类试题更是完全无法用常见的博弈树来进行解答. 寻找必败态即为针对此类试题 ...
- 牛客 - A Simple Game(尼姆博弈变形)
题目链接:点击查看 题目大意:给出 n 个 01 字符串,两个人轮流进行游戏,每次可以选择任意数量的字符串,进行下列操作之一(每个字符串进行的操作可以不同): 选择一个字符串,使得其中的一个 ' 1 ...
- 博弈论(巴什博奕,威佐夫博弈,尼姆博弈)
巴什博奕(Bash Game): 只有一堆n个物品,两个人轮流从中取物,规定每次最少取一个,最多取m个,最后取光者为胜 举一个最简单的例子就是,当n=m+1时,此时不管先手取多少,后手都能把剩下的取完 ...
最新文章
- 机器学习:线性回归简单有效,但是千万不要踩到雷区!
- js进阶 11-22/23 js如何实现选项卡
- 1600: 卡斯丁狗要吃糖葫芦-回文串
- LL-verilog索引向量+-号用法
- Linux 命令之 nslookup 命令-查询域名 DNS 信息的工具
- Flowable 数据库表结构 ACT_RU_TASK
- 无符号右移负数_关于负数的右移与无符号右移运算小结
- XML Tree Editor(树形视图XML编辑器) v0.1.0.35
- 【英语学习】【Daily English】U05 Places L01 How can I get to the city museum?
- eclipse中新建JSP文件时的编码设置
- 算法:罗马数字转换为整数13. Roman to Integer
- PS练习6——文字特效处理
- 数字ic2020海思提前批
- Python 对json文件加密和解密
- idel安装lombok插件安装
- mysql同时更新2个表_mysql中同时update更新多个表
- Itester系列之 HGU_ONU PON性能测试指导
- 新手必看CSDN积分获取方法
- fedora34升级到35
- 微信小程序大小屏幕兼容