这题简直把我坑死了 所有的坑都被我中了

题意:

思路:bfs or 模拟 模拟似乎没有什么坑 但是bfs真的是坑

AC代码:

 #include "iostream"
#include "string.h"
#include "stack"
#include "queue"
#include "string"
#include "vector"
#include "set"
#include "map"
#include "algorithm"
#include "stdio.h"
#include "math.h"
#define ll long long
#define ull unsigned ll
#define mem(a) memset(a,0,sizeof(a))
#define bug cout<<"UUUUUUUUUUUUU\n";
using namespace std;
struct Node{
int xx,yy;
};
int d[][]{{,},{,},{,},{,-},{-,},{-,-},{,-},{-,}};
int flag;
char m[][];
void Bfs(int x,int y){
Node now,next;
int vis[][];
mem(vis);
queue<Node> Q;
while(!Q.empty()) Q.pop();
now.xx=x,now.yy=y;
Q.push(now);
vis[x][y]=;
while(!Q.empty()){
now=Q.front();
Q.pop();
for(int i=; i<; i++){
next.xx=now.xx+d[i][];
next.yy=now.yy+d[i][];
int s=;
int f=;
if(m[now.xx][now.yy]=='x') f=;
if(!vis[next.xx][next.yy]&&(next.xx>&&next.xx<&&next.yy>&&next.yy<&&(m[next.xx][next.yy]=='.'||m[next.xx][next.yy]=='x'))){
Q.push(next);
vis[next.xx][next.yy]=;
}
while(next.xx>&&next.xx<&&next.yy>&&next.yy<&&(m[next.xx][next.yy]=='.'||m[next.xx][next.yy]=='x')){
s++;
if(m[next.xx][next.yy]=='x') f++; //printf("%d %d\n%d %d %d\n",s,f,next.xx,next.yy,i);
if(s==&&f>=) {printf("YES\n");flag=;return;}
next.xx+=d[i][];
next.yy+=d[i][];
}
}
}
}
int main(){
mem(m);
int x1,y1;
for(int i=; i<=; ++i)
for(int j=; j<=; ++j)
cin>>m[i][j];
for(int i=; i<; ++i){
for(int j=; j<; ++j){
if(!flag&&(m[i][j]=='.'||m[i][j]=='x')) Bfs(i,j);
}
}
if(!flag) printf("NO\n");
return ;
}
/*
o.x.
o...
.x..
ooxx x.ox
ox..
x.o.
oo.x xoxx
..x.
o.oo
x.o.
*/

bfs 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. [CareerCup] 17.2 Tic Tac Toe 井字棋游戏

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

  6. Epic - Tic Tac Toe

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

  7. python 井字棋(Tic Tac Toe)

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

  8. ACM-Team Tic Tac Toe

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

  9. CodeForces - 754B Ilya and tic-tac-toe game

    简单搜索 判断是否能在最后一步下棋得到胜利 问题转化为 是否有可以胜利的x的摆法 那么就只有两种情况 1.有两个x相连 并且 在端点还有.可以落子 那么就可以在最后一步 胜利 2.两个x中间恰好有一个 ...

随机推荐

  1. 不一样的dynamic解析json 万能方法

    写过javascript的人都知道js解析json 1:(JSON) 字符串转换为对象. var str = '{"name":"lsw","hobb ...

  2. Python 30分钟入门——数据类型 and 控制结构

    Python是一门脚本语言,我也久闻大名,但正真系统的接触学习是在去年(2013)年底到今年(2014)年初的时候.不得不说的是Python的官方文档相当齐全,如果你是在Windows上学习Pytho ...

  3. java--连接SQL数据库获取验证码

    1.导入SQL相关的包: 可以下载:mysql-connector-java-5.1.39-bin.jar 将包导入到工程的方法:project(在工程名上点鼠标右键) -> Build Pat ...

  4. 添加OSG各种事件处理器

    // add the state manipulator viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera ...

  5. SVN安装及使用

    1.SVN的安装 1.1 安装软件 以下图1中两个图标,分别是SVN服务器端和客户端安装软件 图1 1.2 服务器安装步骤 先点击图1第一个图标,安装SVN的服务器,默认安装即可,安装成功的界面如下图 ...

  6. 基于ACE的c++线程封装

    1. 基本需求 1) 一个基类,其某个方法代表一个线程的生命运行周期.之后通过继承自这个基类来实现个性化线程类: 2) 具备类似QObject的定时器设置功能: 3) 提供在线程对象中同步和异步执行方 ...

  7. KAOS模型

    问题描述: 我们开发了一种针对时序数据的文件格式TSFile,本身不支持sql查询.为了让公司分析人员能够用SQL进行分析,并且应用一些机器学习算法进行预测,需要设计并实现一个TSFile与Spark ...

  8. 关于控件的Invoke(...)方法和BeginInvoke(...)方法的区别

    这两个方法最主要的区别就是一个是同步,一个是异步,即会阻塞线程,那么阻塞哪个线程呢?我们用代码来分析(工具是VS2010) using System; using System.Collections ...

  9. PHPCMS v9 安全防范教程

    一.目录权限设置很重要:可以有效防范黑客上传木马文件.如果通过 chmod 644 * -R 的话,php文件就没有权限访问了.如果通过chmod 755 * -R 的话,php文件的权限就高了. 所 ...

  10. 如何比较日期类型的String 大小浅谈.

    有三种解决方法: 第一种直接用字符串类的compareTo方法: String t1="20160707"; String t2="20160708"; int ...