简单搜索

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

问题转化为 是否有可以胜利的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. C#中this指针的用法示例

    这篇文章主要介绍了C#中this指针的用法,对初学者而言是非常重要的概念,必须加以熟练掌握,需要的朋友可以参考下. 本文实例展示了C#中this指针的用法,对于初学者进一步牢固掌握C#有很大帮助,具体 ...

  2. 【转】一个Java对象到底占多大内存?

    最近在读<深入理解Java虚拟机>,对Java对象的内存布局有了进一步的认识,于是脑子里自然而然就有一个很普通的问题,就是一个Java对象到底占用多大内存? 在网上搜到了一篇博客讲的非常好 ...

  3. 3. UITest笔记

    1.    XCUIApplication *app = [[XCUIApplication alloc] init]; App为查询的入口,当界面发生变化,查询数也会随之更新. 即使是先前存储的XC ...

  4. js中json处理总结之JSON.parse

    踩过的坑都将成为路上的风景.队友在cookie中已存以下值: address_info {"address_name":"人民大会堂","...lng ...

  5. [转] Figuring out why my SVCHOST.EXE is at 100% CPU without complicated tools in Windows 7

    (转自:Figuring out why my SVCHOST.EXE is at 100% CPU without complicated tools in Windows 7 - Scott Ha ...

  6. HYSBZ 1086 王室联邦 (树的分块)

    题意:国王想把他的国家划分成若干个省.他的国家有n个城市,是一棵树,即n-1条边,编号为1..n.为了防止管理太过分散,每个省至少要有B个城市,为了能有效的管理,每个省最多只有3B个城市.每个省必须有 ...

  7. Charles Petzold 编程界大师,世界顶级技术作家 《CODE》值得阅读

    <CODE>The Hidden Language of Computer Hardware and Software 从书内容的第一页开始就惊叹于作者的耐心和责任心 整本书以两个隔街对窗 ...

  8. C++中static,extern和extern "C"关键字

    1. extern 变量 extern 表明该变量在别的地方已经定义过了,在这里要使用那个变量. 当extern不与"C"在一起修饰变量或函数时,如在头文件中: extern in ...

  9. ios之数据持久化

    9.1 数据持久化概述 iOS中可以有四种持久化数据的方式: 属性列表.对象归档.SQLite3和Core Data 9.2 iOS应用程序目录结构 iOS应用程序运行在Mac os模拟器时候,有一下 ...

  10. Ahoi2014&Jsoi2014 支线剧情

    题目描述 题解: 每条边至少经过一次,说明经过下界为$1$. 然后套有源汇上下界最小费用可行流板子. 口胡一下. 此类问题的建图通式为: 1.假设原来的边流量上下界为$[l,r]$,那么在新图中建流量 ...