简单搜索

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

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

那么就只有两种情况

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

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

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

 #include <iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <map>
#include <queue>
#include <fstream>
#define READ() freopen("in.txt", "r", stdin);
using namespace std; typedef pair<int,int> P; char maze[][];
struct Point
{
int x, y;
}point[];
int num = ;
int d[][] = {-, , -, , , , , , , , , -, , -, -, -};
bool vis[][];
bool OK(int x, int y)
{
if (x < || x >= || y < || y >= ) return false;
return true;
}
bool Search()
{ queue<P> que;
for (int i = ; i < num; i++)
{
que.push(P(point[i].x, point[i].y));
}
// memset(vis, 0, sizeof(vis));
while (!que.empty())
{
P p = que.front();
que.pop();
// if(vis[p.first][p.second]) continue;
// vis[p.first][p.second] = true;
//假设是作为端点 的点
for (int i = ; i < ; i++)
{
int nx = p.first+d[i][], ny = p.second+d[i][];
if (!OK(nx, ny)) continue;
if (maze[nx][ny] == 'x')
{
nx += d[i][];
ny += d[i][];
if (!OK(nx, ny)) continue;
if (maze[nx][ny] == 'x')
{
return true;
}
}
}
//假设是作为中间的点
for (int i = ; i < ; i++)
{
int nx = p.first+d[i][], ny = p.second+d[i][];
if (!OK(nx, ny)) continue;
if (maze[nx][ny] == 'x')
{
nx = p.first-d[i][], ny = p.second-d[i][];
if (!OK[nx][ny]) continue;
if (maze[nx][ny] == 'x')
{
return true;
}
}
}
}
return false; }
int main()
{
READ()
for (int i = ; i < ; i++)
{
for (int j = ; j < ; j++)
{
scanf("%c", &maze[i][j]);
if (maze[i][j] == '.')
{
point[num].x = i;
point[num].y = j;
num++;
}
}
getchar();
}
if (Search()) cout << "YES" << endl;
else cout << "NO" << endl;
}

CodeForces - 754B Ilya and tic-tac-toe game的更多相关文章

  1. Principle of Computing (Python)学习笔记(7) DFS Search + Tic Tac Toe use MiniMax Stratedy

    1. Trees Tree is a recursive structure. 1.1 math nodes https://class.coursera.org/principlescomputin ...

  2. POJ 2361 Tic Tac Toe

    题目:给定一个3*3的矩阵,是一个井字过三关游戏.开始为X先走,问你这个是不是一个合法的游戏.也就是,现在这种情况,能不能出现.如果有人赢了,那应该立即停止.那么可以知道X的步数和O的步数应该满足x= ...

  3. 【leetcode】1275. Find Winner on a Tic Tac Toe Game

    题目如下: Tic-tac-toe is played by two players A and B on a 3 x 3 grid. Here are the rules of Tic-Tac-To ...

  4. 2019 GDUT Rating Contest III : Problem C. Team Tic Tac Toe

    题面: C. Team Tic Tac Toe Input file: standard input Output file: standard output Time limit: 1 second M ...

  5. bfs codeforces 754B Ilya and tic-tac-toe game

    这题简直把我坑死了 所有的坑都被我中了 题意: 思路:bfs or 模拟 模拟似乎没有什么坑 但是bfs真的是坑 AC代码: #include "iostream" #includ ...

  6. [CareerCup] 17.2 Tic Tac Toe 井字棋游戏

    17.2 Design an algorithm to figure out if someone has won a game oftic-tac-toe. 这道题让我们判断玩家是否能赢井字棋游戏, ...

  7. Epic - Tic Tac Toe

    N*N matrix is given with input red or black.You can move horizontally, vertically or diagonally. If ...

  8. python 井字棋(Tic Tac Toe)

    说明 用python实现了井字棋,整个框架是本人自己构思的,自认为比较满意.另外,90%+的代码也是本人逐字逐句敲的. minimax算法还没完全理解,所以参考了这里的代码,并作了修改. 特点 可以选 ...

  9. ACM-Team Tic Tac Toe

    我的代码: #include <bits/stdc++.h> using namespace std; int main() { char a[3][3]; int i,j=0; for( ...

随机推荐

  1. canvas基础绘制-arc

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. 微信小程序 逻辑层

    1. 注册程序小程序APP在小程序的根目录下有一个app.js文件.有App(Object),App() 函数用来注册一个小程序.接受一个 Object 参数,其内便是小程序的生命周期.App() 必 ...

  3. 用vue做一个酷炫的menu

    写在前面 最近看到一个非常酷炫的menu插件,一直想把它鼓捣成vue形式,谁让我是vue的死灰粉呢,如果这都不算爱

  4. java读取大文件 超大文件的几种方法

    java 读取一个巨大的文本文件既能保证内存不溢出又能保证性能       import java.io.BufferedReader; import java.io.File; import jav ...

  5. 在windows上安装Jenkins---tomcat流

    在windows上安装Jenkins有两种方式: (1)jar流 在命令行中运行:java -jar jenkins.war 浏览器访问 localhost:8080,创建初始管理员帐号即可. (2) ...

  6. Android安卓下拉阻尼效果实现原理及简单实例

    原理  这种效果是通过自定义控件的方式来实现的,我自定义了一个控件类型,这个自定义控件(PullDownDumperLayout)继承自线性布局(LinearLayout).  用户可以下拉弹出的那个 ...

  7. pycharm 用远程环境时报错bash: line 0: cd: /home/tmp: No such file or directory

    delete redundant path

  8. win10 配置系统默认utf-8编码

    win10 配置系统默认utf-8编码 系统  win10 配置系统默认utf-8编码 Windows系统默认字符编码为gbk编码,开发项目编码一般为UTF-8,在我们执行程序及进行程序编码过程中编码 ...

  9. 如何使用postman访问网站

    1.输入Request URL2.选择Request Method3.输入需要的Request Headers注意:一般token会在Headers中

  10. django--基础操作

    Django基础操作 django常用命令 创建django项目 django-admin startproject mysite 创建项目完成以后,文件目录结构为: 修改settings文件内容 A ...