bfs codeforces 754B Ilya and tic-tac-toe game
这题简直把我坑死了 所有的坑都被我中了

题意:
思路: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的更多相关文章
- 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 ...
- POJ 2361 Tic Tac Toe
题目:给定一个3*3的矩阵,是一个井字过三关游戏.开始为X先走,问你这个是不是一个合法的游戏.也就是,现在这种情况,能不能出现.如果有人赢了,那应该立即停止.那么可以知道X的步数和O的步数应该满足x= ...
- 【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 ...
- 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 ...
- [CareerCup] 17.2 Tic Tac Toe 井字棋游戏
17.2 Design an algorithm to figure out if someone has won a game oftic-tac-toe. 这道题让我们判断玩家是否能赢井字棋游戏, ...
- Epic - Tic Tac Toe
N*N matrix is given with input red or black.You can move horizontally, vertically or diagonally. If ...
- python 井字棋(Tic Tac Toe)
说明 用python实现了井字棋,整个框架是本人自己构思的,自认为比较满意.另外,90%+的代码也是本人逐字逐句敲的. minimax算法还没完全理解,所以参考了这里的代码,并作了修改. 特点 可以选 ...
- ACM-Team Tic Tac Toe
我的代码: #include <bits/stdc++.h> using namespace std; int main() { char a[3][3]; int i,j=0; for( ...
- CodeForces - 754B Ilya and tic-tac-toe game
简单搜索 判断是否能在最后一步下棋得到胜利 问题转化为 是否有可以胜利的x的摆法 那么就只有两种情况 1.有两个x相连 并且 在端点还有.可以落子 那么就可以在最后一步 胜利 2.两个x中间恰好有一个 ...
随机推荐
- grep-2.26 sed-4.2.2 awk-4.1.4 wget-1.18 pcregrep-8.39 pcre2grep-10.22 for windows 最新版本静态编译
-------------------------------------------------------------------------------------------- grep (G ...
- Installing Selenium and ChromeDriver on Ubuntu
I recently got Selenium, Google Chrome, and ChromeDriver installed and working on a DigitalOcean ins ...
- 【转】Caffe初试(九)solver及其设置
solver算是caffe的核心的核心,它协调着整个模型的运作.caffe程序运行必带的一个参数就是solver配置文件.运行代码一般为 #caffe train --solver=*_solver. ...
- OE学习笔记流水
Terrain.cpp中的getWorldCoordsUnderMouse函数,进行标记.
- Linux更改计算机名称
1.修改:vim /etc/hosts 2.修改:vim /etc/sysconfig/network 3.重启:reboot 如不重启可以输入:hostname 新改的计算机名称,然后su
- unity的固定管线shader
最近shader学习中,看的视频. 练习的固定管线的shader如下: ps.在unity5中半透明不好用,其他的还好 //不区分大小写 //这是固定管线的Shader Shader "Sh ...
- docker搭建Hadoop集群
一个分布式系统基础架构,由Apache基金会所开发. 用户可以在不了解分布式底层细节的情况下,开发分布式程序.充分利用集群的威力高速运算和存储. 首先搭建Docker环境,Docker版本大于1.3. ...
- 从ord()中对Unicode编码的理解
刚开始学习编程的时候,老对字符串编码的理解模模糊糊.也一直看这方便的资料,今天在看Dive in python时,突然有了新的理解(不知道是否正确). Python有个built-in函数ord(), ...
- Python帮助文档中Iteration iterator iterable 的理解
iteration这个单词,是循环,迭代的意思.也就是说,一次又一次地重复做某件事,叫做iteration.所以很多语言里面,循环的循环变量叫i,就是因为这个iteration. iteration指 ...
- 基于SOUI开发的应用展示
本页面列出基于SOUI开发的产品 欢迎使用SOUI的朋友提供资源:setoutsoft#qq.com #->@ 千万级平台后台在线监测客户端 1, 主页:用于显示管理服务端在线情况,左侧栏包括 ...