zoukankan      html  css  js  c++  java
  • Ancient Go---hdu5546(dfs爆搜CCPC题目)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5546

    题意就是两个人下围棋,问在下一颗x是否能杀死o,'.'是空位子;

    枚举所有的点,判断是否合法即可;

    #include <iostream>
    #include <stdio.h>
    #include <string.h>
    #include <string>
    #include <vector>
    #include <algorithm>
    #include <map>
    #include <queue>
    #include <stack>
    #include <math.h>
    
    using namespace std;
    
    #define met(a, b) memset(a, b, sizeof(a))
    #define N 103
    #define INF 0x3f3f3f3f
    
    typedef long long LL;
    
    int dir[4][2] = { {1,0}, {-1,0}, {0,-1}, {0,1} };
    char s[N][N];
    int vis[N][N];
    
    int OK(int x, int y)
    {
        return (x<9 && y<9 && x>=0 && y>=0);
    }
    
    int check(int x, int y)
    {
        vis[x][y] = 1;
        for(int i=0; i<4; i++)
        {
            int px = x+dir[i][0];
            int py = y+dir[i][1];
            if(!OK(px, py) || vis[px][py])continue;
            if(s[px][py] == '.')
                return 1;
            if(s[px][py] == 'o' && check(px, py))
                return 1;
        }
        return 0;
    }
    
    int Judge(int x, int y)
    {
        for(int i=0; i<4; i++)
        {
            int px = x + dir[i][0];
            int py = y + dir[i][1];
            if(!OK(px, py))continue;
            if(s[px][py] == 'o')
            {
                met(vis, 0);
                if(!check(px, py))
                    return 1;///不能走出去说明找到了;
            }
        }
        return 0;
    }
    
    int solve()
    {
        for(int i=0; i<9; i++)
        {
            for(int j=0; j<9; j++)
            {
                if(s[i][j] == 'x' || s[i][j] == 'o')continue;
                s[i][j] = 'x';
                if(Judge(i, j))return 1;
                s[i][j] = '.';
            }
        }
        return 0;
    }
    
    int main()
    {
        int T, t = 1;
        scanf("%d", &T);
        while(T--)
        {
            for(int i=0; i<9; i++)
            {
                scanf("%s", s[i]);
            }
            int ans = solve();
            if(ans) printf("Case #%d: Can kill in one move!!!
    ", t++);
            else printf("Case #%d: Can not kill in one move!!!
    ", t++);
        }
        return 0;
    }
    View Code
  • 相关阅读:
    ADPlus
    'telnet' is not recognized as an internal or external command
    图片二进制上传2
    window.opener返回值的用法
    UrlRewriter 重写的问题
    缩略图 水印
    读取二进制图片问题
    正则表达式匹配问题
    .NET读excl数据
    js调用其他页面输出内容
  • 原文地址:https://www.cnblogs.com/zhengguiping--9876/p/5731467.html
Copyright © 2011-2022 走看看