hdu 2147(巴什博弈+NP图)
kiki's game
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 40000/10000 K (Java/Others)
Total Submission(s): 9663 Accepted Submission(s): 5817
in his mind, she just playes the checkerboard game.The size of the
chesserboard is n*m.First of all, a coin is placed in the top right
corner(1,m). Each time one people can move the coin into the left, the
underneath or the left-underneath blank space.The person who can't make a
move will lose the game. kiki plays it with ZZ.The game always starts
with kiki. If both play perfectly, who will win the game?
contains multiple test cases. Each line contains two integer n, m
(0<n,m<=2000). The input is terminated when n=0 and m=0.
5 4
6 6
0 0
(1) 所有终结点是必败点(P点);
(2) 从任何必胜点(N点)操作,至少有一种方法可以进入必败点(P点);
(3)无论如何操作, 从必败点(P点)都只能进入必胜点(N点).
取子游戏算法实现:
步骤1:将所有终结位置标记为必败点(P点);
步骤2: 将所有一步操作能进入必败点(P点)的位置标记为必胜点(N点)
步骤3:如果从某个点开始的所有一步操作都只能进入必胜点(N点) ,则将该点标记为必败点(P点) ;
步骤4: 如果在步骤3未能找到新的必败(P点),则算法终止;否则,返回到步骤2。
拿5*6的矩阵举个例子:
首先:根据第一步,我们可以确定 (n,1) 是终结位置,标记为 P
然后画出NP图:
PNPNPN
NNNNNN
PNPNPN
NNNNNN
PNPNPN
可以发现这个图是kiki赢,然后找一下里面子图的规律,比如说红色的子图,发现只有当 n 和 m都为奇数时,第一个点才会是必败点,其余情况都是必胜点。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
using namespace std;
int n,m;
int main()
{
while(scanf("%d%d",&n,&m)!=EOF,n+m){
if(n%==&&m%==){
printf("What a pity!\n");
continue;
}else printf("Wonderful!\n");
}
return ;
}
hdu 2147(巴什博弈+NP图)的更多相关文章
- Hdu 2147 巴什博弈 PN图
P:先手必输 N:先手必胜 PN图规则:如果一个点能转换到的所有点都是N,那么此点状态为P.若能转化到一个P,即使对手面临必输状态,此点为N. 然后找规律就行 #include<bits/s ...
- hdu 1849(巴什博弈)
Rabbit and Grass Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu 1846(巴什博弈)
Brave Game Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- hdu 2897 巴什博弈变形 ***
大意:一堆石子共有n个,A,B两人轮流从中取,每次取的石子数必须在[p,q]区间内,若剩下的石子数少于p个,当前取者必须全部取完.最后取石子的人输.给出n,p,q,问先取者是否有必胜策略? Bash博 ...
- HDU 2147 P/N博弈
点这里去做题 如图 找必胜点和必败点, 1.终点为必胜点 2.所有能一步走到必胜点的都是必败点 3.每一步都只能走到必败点的是必胜点 #include<bits/stdc++.h> usi ...
- HDU - 1847 巴什博弈
思路: 0 1 2 3 4 5 6 7 8 9 10 11 12 P N N P N N P N N P N N P 不难发现:当n为三的倍数时,KIKI ...
- hdu 4764 巴什博弈
Stone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Subm ...
- HDU 2147 找规律博弈
题目大意: 从右上角出发一直到左下角,每次左移,下移或者左下移,到达左下角的人获胜 到达左下角为必胜态,那么到达它的所有点都为必败态,每个点的局势都跟左,下,左下三个点有关 开始写了一个把所有情况都计 ...
- hdu 2147 kiki's game(巴什博弈)
kiki's game HDU - 2147 题意:一个n*m的表格,起始位置为右上角,目标位置为左下角,甲先开始走,走的规则是可以向左,向下或者向左下(对顶的)走一格.谁先走到目标位置谁就胜利.在甲 ...
随机推荐
- JavaScript定义类与对象的一些方法
最近偶然碰到有朋友问我"hoisting"的问题.即在js里所有变量的声明都是置顶的,而赋值则是在之后发生的.可以看看这个例子: 1 var a = 'global'; 2 (fu ...
- Application Error - The connection to the server was unsuccessful. (file:///android_asset/www/index.html)
问题描述: PhoneGap+Sencha Touch开发的应用,打包后的APP或者调试期间,在启动的时候提示如下信息: Application Error - The connection to t ...
- Codeforces Round #331 (Div. 2) B. Wilbur and Array
B. Wilbur and Array time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Python学习笔记(Django篇)——3、创建第一个数据库模型
Django里面集成了SQLite的数据库,对于初期研究来说,可以用这个学习. 第一步,创建数据库就涉及到建表等一系列的工作,在此之前,要先在cmd执行一个命令: python manage.py ...
- java后台svg转成png
1.替换img地址 /** * 替换img地址 * @param str -- 前台svg字符串 * @return */ private String transferImgPath(HttpSer ...
- [C#] 类型学习笔记一:CLR中的类型,装箱和拆箱
在学习.NET的时候,因为一些疑问,让我打算把.NET的类型篇做一个总结.总结以三篇博文的形式呈现. 这篇博文,作为三篇博文的第一篇,主要探讨了.NET Framework中的基本类型,以及这些类型一 ...
- Jade模板引擎学习(二)语法:代码、变量、循环、过滤器及mixin
Jade语法 一.代码 不会被缓冲代码 ul - for(var i=0; i; i++) li Jade Engine 会转换为: <ul> <li>Jade Engine& ...
- 深入探索C++对象模型(二)
构造函数语义学(The Semantics of Constructors) Default Constructor的构造操作 对于class X,如果没有任何user-declared constr ...
- 「模板」网络最大流 FF && EK && Dinic && SAP && ISAP
话不多说上代码. Ford-Fulkerson(FF) #include <algorithm> #include <climits> #include <cstdio& ...
- JNLP Slave connection error解决办法
Replace in jnlp-file <argument>-workDir</argument> <argument /> with <argume ...