• 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
  • 相关阅读:
    C++类内存分布
    职场人理财之指数基金篇
    职场之殇---有些事情千万不能做
    职场人为什么需要理财
    职场发展之跟对老板有多重要
    职场中怎么做好一个演讲
    多线程如何按指定顺序同步执行
    多线程抢票系统浅析
    Spring Boot进阶系列三
    Spring Boot进阶系列二
  • 原文地址:https://www.cnblogs.com/zhengguiping--9876/p/5731467.html
Copyright © 2020-2023  润新知