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

Posted %%%%%

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了bfs codeforces 754B Ilya and tic-tac-toe game相关的知识,希望对你有一定的参考价值。

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

题意:

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

AC代码:

 1 #include "iostream"
 2 #include "string.h"
 3 #include "stack"
 4 #include "queue"
 5 #include "string"
 6 #include "vector"
 7 #include "set"
 8 #include "map"
 9 #include "algorithm"
10 #include "stdio.h"
11 #include "math.h"
12 #define ll long long
13 #define ull unsigned ll
14 #define mem(a) memset(a,0,sizeof(a))
15 #define bug cout<<"UUUUUUUUUUUUU\\n";
16 using namespace std;
17 struct Node{
18     int xx,yy;
19 };
20 int d[8][2]{{1,1},{1,0},{0,1},{1,-1},{-1,0},{-1,-1},{0,-1},{-1,1}};
21 int flag;
22 char m[10][10];
23 void Bfs(int x,int y){
24     Node now,next;
25     int vis[10][10];
26     mem(vis);
27     queue<Node> Q;
28     while(!Q.empty()) Q.pop();
29     now.xx=x,now.yy=y;
30     Q.push(now);
31     vis[x][y]=1;
32     while(!Q.empty()){
33         now=Q.front();
34         Q.pop();
35         for(int i=0; i<8; i++){
36             next.xx=now.xx+d[i][0];
37             next.yy=now.yy+d[i][1];
38             int s=1;
39             int f=0;
40             if(m[now.xx][now.yy]==\'x\') f=1;
41             if(!vis[next.xx][next.yy]&&(next.xx>0&&next.xx<5&&next.yy>0&&next.yy<5&&(m[next.xx][next.yy]==\'.\'||m[next.xx][next.yy]==\'x\'))){
42                 Q.push(next);
43                 vis[next.xx][next.yy]=1;
44             }
45             while(next.xx>0&&next.xx<5&&next.yy>0&&next.yy<5&&(m[next.xx][next.yy]==\'.\'||m[next.xx][next.yy]==\'x\')){
46                 s++;
47                 if(m[next.xx][next.yy]==\'x\') f++; //printf("%d %d\\n%d %d %d\\n",s,f,next.xx,next.yy,i);
48                 if(s==3&&f>=2) {printf("YES\\n");flag=1;return;}
49                 next.xx+=d[i][0];
50                 next.yy+=d[i][1];
51             }
52         }
53     }
54 }
55 int main(){
56     mem(m);
57     int x1,y1;
58     for(int i=1; i<=4; ++i)
59         for(int j=1; j<=4; ++j)
60             cin>>m[i][j];
61     for(int i=1; i<5; ++i){
62         for(int j=1; j<5; ++j){
63             if(!flag&&(m[i][j]==\'.\'||m[i][j]==\'x\')) Bfs(i,j);
64         }
65     }
66     if(!flag) printf("NO\\n");
67     return 0;
68 }
69 /*
70 o.x.
71 o...
72 .x..
73 ooxx
74 
75 x.ox
76 ox..
77 x.o.
78 oo.x
79 
80 xoxx
81 ..x.
82 o.oo
83 x.o.
84 */

 

以上是关于bfs codeforces 754B Ilya and tic-tac-toe game的主要内容,如果未能解决你的问题,请参考以下文章

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

codeforces 842C Ilya And The Tree

●CodeForces 518D Ilya and Escalator

Codeforces 518D Ilya and Escalator

C - Ilya And The Tree Codeforces Round #430 (Div. 2)

Ilya And The Tree CodeForces - 842C