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 ...
随机推荐
- Android图片加载神器之Fresco,基于各种使用场景的讲解
Fresco是Facebook开源Android平台上一个强大的图片加载库,也是迄今为止Android平台上最强大的图片加载库. 优点:相对于其他开源的第三方图片加载库,Fresco拥有更好的内存管理 ...
- android特效集合
https://github.com/Trinea/android-open-project http://www.cnblogs.com/hawkon/p/3593709.html http://i ...
- 关于Oracle中sysoper这个系统权限的问题
我们都知道Oracle数据库安装完之后.默认的会有这样几个系统角色或权限.nomal,sysdba,sysoper等等,之前每次登录Oracle的时候.都是直接以conn / as sysdba 的身 ...
- css3 position fixed居中的问题
通常,我们要让某元素居中,会这样做: #element{ margin:0 auto; } 假设还想让此元素位置固定呢?一般我们会加入position:fixed,例如以下: #element{ po ...
- Django-select_related优化查询
对于一对一字段(OneToOneField)和外键字段(ForeignKey),可以使用select_related 来对QuerySet进行优化. select_related 返回一个QueryS ...
- kubernetes之多容器pod以及通信
系列目录 容器经常是为了解决单一的,窄范围的问题,比如说微服务.然而现实中,一些复杂问题的完成往往需要多个容器.这里我们讨论一下如何把多个容器放在同一个pod里以及容器间的通信 什么是pod pod是 ...
- 关于input:-webkit-autofill样式问题
最近在整理项目的时候,遇到了一个chrome浏览器自动填充的样式问题, 用户名跟密码的input都设置为透明颜色,但是会变成黄色,打开chrome调试工具,发现有个input:-webkit-auto ...
- cocos2dx-3.1 接入多盟广告sdk+Android (2)
上篇,把基本工作做完了,接下来,在C++下加入代码. 1.打开win32下的project,加入一个类.DomobAd.代码例如以下, <pre name="code" cl ...
- java 定义一个同步map内存去重法
实例:
- A20 烧录和启动 log
用 LiveSuit 烧写了一个 lubuntu 的映像文件到板子上, 同时接了串口观察烧录过程的串口打印信息, 如下 ES: FES:Fes Ver: 098 FES:=============== ...