HDOJ1564Play a game(找规律博弈)

47 篇文章 0 订阅

原题--题目链接

题目大意:题目意思是输出里面的两个人玩走方格的游戏,谁走了最后一步就赢了

这道题一开始木有思路,后来想了一下搜索,就大概试了一下,代码如下:

#include <iostream>
#include <cstdio>
#include <string>
#include <string.h>
#include <map>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
using namespace std;
int min(int a, int b)
{
    if(a<=b)
        return a;
    return b;
}
int max(int a, int b)
{
    if(a>=b)
        return a;
    return b;
}
double min(double a, double b)
{
    if(a<=b)
        return a;
    return b;
}
double max(double a, double b)
{
    if(a>=b)
        return a;
    return b;
}
int n ;
int s[1010][1010] ;
int direct[4][2] = {-1,0,1,0,0,-1,0,1} ;
int DFS(int x, int y)
{
    int x1, y1;
    int i, ans ;
    for (i = 0 ; i < 4 ; i++)
    {
        x1 = x + direct[i][0] ;
        y1 = y + direct[i][1] ;
        if (x1 < 0 || x1 >= n) continue ;
        if (y1 < 0 || y1 >= n) continue ;//判定是否在图内
        if (s[x1][y1]) continue ;
        s[x1][y1] = 1 ;
        ans = DFS(x1, y1) ;
        s[x1][y1] = 0 ;
        if (ans == 0)
        return 1 ;   //如果下一点是必败点  那么该点一定是必胜点;
    }
    return 0;
}
int main ()
{
    s[0][0] = 1 ;
    for (n = 1 ; n <= 7; n++)
        printf ("%d, %d\n", n, DFS(0,0)) ;
    return 0;
}
通过搜索前几个数字,发现这个和n的奇偶性有关,在看了其他的一些讨论,都得出来奇偶性的特点

#include <iostream>
#include <cstdio>
#include <string>
#include <string.h>
#include <map>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
using namespace std;
int min(int a, int b)
{
    if(a<=b)
        return a;
    return b;
}
int max(int a, int b)
{
    if(a>=b)
        return a;
    return b;
}
double min(double a, double b)
{
    if(a<=b)
        return a;
    return b;
}
double max(double a, double b)
{
    if(a>=b)
        return a;
    return b;
}
int main()
{
    int n;
    while(scanf("%d",&n),n)
    {
        if(!(n %= 2))
            printf("8600\n");
        else printf("ailyanlu\n");
    }
    return 0;
}
还有什么办法呢?



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值