HDU2147 kiki's game (SG表找规律)
InputInput 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.
OutputIf kiki wins the game printf "Wonderful!", else "What a pity!".
Sample Input
5 3
5 4
6 6
0 0
Sample Output
What a pity!
Wonderful!
Wonderful!
题意:
开始棋子在(n,m),每次可向左,或向上,或左上走一步。走到(1,1)者胜利。
没有什么好的思路,SG函数转移没问题,但是MLE,所以打表找规律。
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=;
int SG[maxn+][maxn+];
int ex[maxn],n,m;
void solve()
{
int times=;
for(int i=;i<=maxn;i++)
for(int j=;j<=maxn;j++)
{
if(i==&&j==){
SG[i][j]=;
continue;
}
times++;
if(i>) ex[SG[i-][j]]=times;
if(j>) ex[SG[i][j-]]=times;
if(i>&&j>) ex[SG[i-][j-]]=times;
for(int k=;k<;k++){
if(ex[k]!=times) {
SG[i][j]=k; break;
}
}
}
}
int main()
{
solve();
for(int i=;i<=;i++){
for(int j=;j<=;j++){
if(SG[i][j]) printf("P ");
else printf("N ");
}
printf("\n");
}
}
N P N P N P N P N P
P P P P P P P P P P
N P N P N P N P N P
P P P P P P P P P P
N P N P N P N P N P
P P P P P P P P P P
N P N P N P N P N P
P P P P P P P P P P
N P N P N P N P N P
P P P P P P P P P P Process exited normally.
Press any key to continue . . .
发现n和m都为奇数点才是必胜N态。
但是至于证明,我暂时还没想到。
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int n,m;
int main()
{
while(~scanf("%d%d",&n,&m)){
if(n==&&m==) return ;
n%=; m%=;
if(n==||m==) printf("Wonderful!\n");
else printf("What a pity!\n");
} return ;
}
一个小时后,突然想起10000kb的内存,用bool应该没问题,果然。
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=;
bool SG[maxn+][maxn+];
int n,m;
void solve()
{
for(int i=;i<=maxn;i++)
for(int j=;j<=maxn;j++)
{
if(i==&&j==){
SG[i][j]=false;
continue;
}
if(i>&&!SG[i-][j]) SG[i][j]=true;
if(j>&&!SG[i][j-]) SG[i][j]=true;
if(i>&&j>&&!SG[i-][j-]) SG[i][j]=true;
}
}
int main()
{
solve();
while(~scanf("%d%d",&n,&m)){
if(n==&&m==) return ;
if(SG[n][m]) printf("Wonderful!\n");
else printf("What a pity!\n");
} return ;
}
HDU2147 kiki's game (SG表找规律)的更多相关文章
- BZOJ 1228 E&G(sg函数+找规律)
把一对石子堆看出一个子游戏.打出子游戏的sg表找规律.. 这个规律我是一定找不出来的... 对于i,j,如果 (i-1)%pow(2,k+1) < pow(2,k) (j-1)%pow(2,k+ ...
- hdu 3032 Nim or not Nim? (SG函数博弈+打表找规律)
Nim or not Nim? Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Sub ...
- HDU 5795 A Simple Nim(SG打表找规律)
SG打表找规律 HDU 5795 题目连接 #include<iostream> #include<cstdio> #include<cmath> #include ...
- hdu 3032 Nim or not Nim? (sg函数打表找规律)
题意:有N堆石子,每堆有s[i]个,Alice和Bob两人轮流取石子,可以从一堆中取任意多的石子,也可以把一堆石子分成两小堆 Alice先取,问谁能获胜 思路:首先观察这道题的数据范围 1 ≤ N ...
- HDU 3032 (SG打表找规律)
题意: 有n堆石子,alice先取,每次可以选择拿走一堆石子中的1~x(该堆石子总数) ,也可以选择将这堆石子分成任意的两堆.alice与bob轮流取,取走最后一个石子的人胜利. 思路: 因为数的范围 ...
- HDU-4664 Triangulation 博弈,SG函数找规律
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4664 题意:一个平面上有n个点(一个凸多边形的顶点),每次可以连接一个平面上的两个点(不能和已经连接的 ...
- HDU2149-Good Luck in CET-4 Everybody!(博弈,打表找规律)
Good Luck in CET-4 Everybody! Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ...
- hdu_5795_A Simple Nim(打表找规律的博弈)
题目链接:hdu_5795_A Simple Nim 题意: 有N堆石子,你可以取每堆的1-m个,也可以将这堆石子分成3堆,问你先手输还是赢 题解: 打表找规律可得: sg[0]=0 当x=8k+7时 ...
- HDU 3032 multi-sg 打表找规律
普通NIM规则加上一条可以分解为两堆,标准的Multi-SG游戏 一般Multi-SG就是根据拓扑图计算SG函数,这题打表后还能发现规律 sg(1)=1 sg(2)=2 sg(3)=mex{0,1,2 ...
随机推荐
- Python下opencv使用笔记(七)(图像梯度与边缘检測)
梯度简单来说就是求导,在图像上表现出来的就是提取图像的边缘(无论是横向的.纵向的.斜方向的等等),所须要的无非也是一个核模板.模板的不同结果也不同.所以能够看到,全部的这些个算子函数,归结究竟都能够用 ...
- hdu5379||2015多校联合第7场1011 树形统计
pid=5379">http://acm.hdu.edu.cn/showproblem.php? pid=5379 Problem Description Little sun is ...
- AVOS Cloud 技术支持系统开源了
非常高兴跟大家说.工单系统(技术支持系统)开源了.代码托管在了Github上. 假设还未见识过工单系统,请移步于 https://ticket.avosapps.com/ 这个系统是用 AVOS Cl ...
- 手写AngularJS脏检查机制
什么是脏检查 View -> Model 浏览器提供有User Event触发事件的API,例如,click,change等 Model -> View 浏览器没有数据监测API. Ang ...
- Cocos2d-x 3.0final 终结者系列教程15-win7+vs2012+adt+ndk环境搭建(无Cygwin)
最终不用Cygwin 了.非常高兴 为什么要用Win7? 由于VS2012要求Win7以上系统才干安装! 为什么要用vs2012? 由于VS2012才支持C++11! 为什么要支持C++11? 由于C ...
- AngularJs 在控制器中过滤
<html> <head> <title>Simple app</title> <script src="https://ajax.go ...
- jsp 下拉框首字母定位可检索
实现效果如图: 页面部分: (1)js中: (2)body中: JAVA代码部分: 控制器Controller中 写一个页面js中调用的方法: 引入jar包:
- Scala随记
使用Scala首先确保本地Java 8版本,然后按照官网所说,比较流行的方式(1) sbt; (2) IDE "The most popular way to get Scala is ei ...
- Excel表格数据导入Mysql数据库的方法
1.使用Navicat 连接需要导入的数据库. 2.excel 列的名字最好和数据库的名字一致,便于我们直观的查看好理解. 第一步,先创建好表,和准备好对应的excel文件.在Navicat 中选 ...
- PHP 5.6编译安装
yum install openssl openssl-devel libxml2-devel libxml2 bzip2 bzip2-devel curl-devel php-mcrypt libm ...