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

时间:2022-09-16 15:02:38

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

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.
*/