zoukankan      html  css  js  c++  java
  • CodeForces

    简单搜索

    判断是否能在最后一步下棋得到胜利

    问题转化为 是否有可以胜利的x的摆法

    那么就只有两种情况

    1、有两个x相连 并且 在端点还有.可以落子 那么就可以在最后一步 胜利

    2、两个x中间恰好有一个.空着 那么可以再这里落子胜利

    搜索这两种情况 存在则胜利 不存在 则无法再最后一步胜利

     1 #include <iostream>
     2 #include <stdio.h>
     3 #include <string>
     4 #include <string.h>
     5 #include <map>
     6 #include <queue>
     7 #include <fstream>
     8 #define READ() freopen("in.txt", "r", stdin);
     9 using namespace std;
    10 
    11 typedef pair<int,int> P;
    12 
    13 char maze[8][8];
    14 struct Point
    15 {
    16     int x, y;
    17 }point[32];
    18 int num = 0;
    19 int d[8][2] = {-1, 0, -1, 1, 0, 1, 1, 1, 1, 0, 1, -1, 0, -1, -1, -1};
    20 bool vis[8][8];
    21 bool OK(int x, int y)
    22 {
    23     if (x < 0 || x >= 4 || y < 0 || y >= 4) return false;
    24     return true;
    25 }
    26 bool Search()
    27 {
    28 
    29     queue<P> que;
    30     for (int i = 0; i < num; i++)
    31     {
    32         que.push(P(point[i].x, point[i].y));
    33     }
    34    // memset(vis, 0, sizeof(vis));
    35     while (!que.empty())
    36     {
    37         P p = que.front();
    38         que.pop();
    39        // if(vis[p.first][p.second]) continue;
    40        // vis[p.first][p.second] = true;
    41         //假设是作为端点 的点
    42         for (int i = 0; i < 8; i++)
    43         {
    44             int nx = p.first+d[i][0], ny = p.second+d[i][1];
    45             if (!OK(nx, ny)) continue;
    46             if (maze[nx][ny] == 'x')
    47             {
    48                 nx += d[i][0];
    49                 ny += d[i][1];
    50                 if (!OK(nx, ny)) continue;
    51                 if (maze[nx][ny] == 'x')
    52                 {
    53                     return true;
    54                 }
    55             }
    56         }
    57         //假设是作为中间的点
    58         for (int i = 0; i < 8; i++)
    59         {
    60             int nx = p.first+d[i][0], ny = p.second+d[i][1];
    61             if (!OK(nx, ny)) continue;
    62             if (maze[nx][ny] == 'x')
    63             {
    64                 nx = p.first-d[i][0], ny = p.second-d[i][1];
    65                 if (!OK[nx][ny]) continue;
    66                 if (maze[nx][ny] == 'x')
    67                 {
    68                     return true;
    69                 }
    70             }
    71         }
    72     }
    73     return false;
    74 
    75 
    76 }
    77 int main()
    78 {
    79     READ()
    80     for (int i = 0; i < 4; i++)
    81     {
    82         for (int j = 0; j < 4; j++)
    83         {
    84             scanf("%c", &maze[i][j]);
    85             if (maze[i][j] == '.')
    86             {
    87                 point[num].x = i;
    88                 point[num].y = j;
    89                 num++;
    90             }
    91         }
    92         getchar();
    93     }
    94     if (Search()) cout << "YES" << endl;
    95     else cout << "NO" << endl;
    96 }
  • 相关阅读:
    HDU 5059 Help him
    HDU 5058 So easy
    HDU 5056 Boring count
    HDU 5055 Bob and math problem
    HDU 5054 Alice and Bob
    HDU 5019 Revenge of GCD
    HDU 5018 Revenge of Fibonacci
    HDU 1556 Color the ball
    CodeForces 702D Road to Post Office
    CodeForces 702C Cellular Network
  • 原文地址:https://www.cnblogs.com/oscar-cnblogs/p/6435281.html
Copyright © 2011-2022 走看看