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 ...
随机推荐
- Mysql的四种key
我们看到Key那一栏,可能会有4种值,即 '','PRI','UNI','MUL'1. 如果Key是空的, 那么该列值的可以重复, 表示该列没有索引, 或者是一个非唯一的复合索引的非前导列2. 如果K ...
- android-BroadcastReceive广播接收器
应用可以使用它对外部事件进行过滤,只对感兴趣的外部事件(如当电话呼入时,或者数据网络可用时)进行接收并做出响应.广播接收器没有用户界面.然而,它们可以启动一个activity或service来响应它们 ...
- hdoj 2188 悼念512汶川大地震遇难同胞——选拔志愿者 【巴什博弈】
题意:. . . 策略:最简单的典型的巴什博弈. 代码: #include<stdio.h> int main() { int n, m; int t; scanf("%d&qu ...
- SpringBoot学习之验证信息国际化
以登录为例: 1.controller的登录方法: @RequestMapping("/SSOAuth/login") @ResponseBody public ResponseV ...
- How to reset your password in Ubuntu
There are many reasons you might want to reset a password: Someone gave you a computer with Ubuntu i ...
- idea设置提示不区分大小写
- JMeter中使用Put请求方式请求接口
前言 现在有如下接口,是以PUT的方式请求的: 请求URL:IP+Port+/api/v1/apps/{appId} 请求参数: 参数名 必选 类型 nameCn 是 string nameEn 是 ...
- Windows8-x64 VMWare安装Linux CentOS6-x64
本文參考了:http://www.cnblogs.com/seesea125/archive/2012/02/25/2368255.html 其内容相当具体,以至于我还没依照其步骤做完.系统就已经安装 ...
- 分治分块与计算几何练习 [Cloned]
https://cn.vjudge.net/contest/148706 A #include<cstdio> #include<cstring> #include<cm ...
- 开源安卓Android流媒体音视频播放器实现声音自动停止、恢复、一键静音功能源码
本文转自EasyDarwin团队John的博客:http://blog.csdn.net/jyt0551/article/details/60802145 我们在开发安卓Android流媒体音视频播放 ...