754B Ilya and tic-tac-toe game
来源:互联网 发布:无损播放软件 编辑:程序博客网 时间:2024/06/05 08:55
题目链接:
http://codeforces.com/problemset/problem/754/B
题解:
感觉这题直接用暴力去做(虽然自己比较傻的用了BFS做)
代码:
#include <cmath>#include <cstdio>#include <queue>#include <cstring>#include <iostream>#include <algorithm>using namespace std;#define met(a,b) memset(a,b,sizeof(a))#define inf 0x3f3f3f3ftypedef long long ll;int dir[8][2]={1,0,-1,0,0,1,0,-1,1,1,1,-1,-1,1,-1,-1};struct node{ int x,y;};int visited[4][4];char map[4][4];int flag;bool go(int x,int y){ if(0<=x&&x<4&&0<=y&&y<4&&(map[x][y]=='.'||map[x][y]=='x')) return true; return false;}void bfs(int x,int y){ node now,next; queue<node>q; while(!q.empty()) q.pop(); met(visited,0); now.x=x; now.y=y; visited[x][y]=1; q.push(now); while(!q.empty()) { now=q.front(); q.pop(); for(int i=0;i<8;i++) { next.x=now.x+dir[i][0]; next.y=now.y+dir[i][1]; int cnt1=1; int cnt2=0; if(map[now.x][now.y]=='x') cnt2=1; if(!visited[next.x][next.y]&&go(next.x,next.y)) { visited[next.x][next.y]=1; q.push(next); } while(go(next.x,next.y)) { cnt1++; if(map[next.x][next.y]=='x') cnt2++; if(cnt1==3&&cnt2>=2) { printf("YES\n"); flag=1; return; } next.x+=dir[i][0]; next.y+=dir[i][1]; } } }}int main(){ for(int i=0;i<4;i++) scanf("%s",map[i]); flag=0; for(int i=0;i<4;i++) for(int j=0;j<4;j++) if(!flag&&(map[i][j]=='x'||map[i][j]=='.')) bfs(i,j); if(!flag) printf("NO\n");}
0 0
- B. Ilya and tic-tac-toe game
- 【Codeforces 754 B Ilya and tic-tac-toe game】
- 【codeforces 754B】 Ilya and tic-tac-toe game
- Cdoeforces 754 B - Ilya and tic-tac-toe game
- codeforces 754 B Ilya and tic-tac-toe game
- 754B Ilya and tic-tac-toe game
- 754B. Ilya and tic-tac-toe game
- CodeForces 754B Ilya and tic-tac-toe game
- Codeforces-754B-Ilya and tic-tac-toe game(简单模拟判断)
- Codeforces Round #390(Div. 2)B. Ilya and tic-tac-toe game【模拟】
- Codeforces Round #390 (Div. 2)-B Ilya and tic-tac-toe game(模拟)
- Codeforces Round #390 (Div. 2) B. Ilya and tic-tac-toe game(dfs)
- Codeforces Round #390 (Div. 2)B Ilya and tic-tac-toe game
- Codeforces #390 (Div. 2) B. Ilya and tic-tac-toe game ( DFS
- 2017寒假集训-小题训练1:F - Ilya and tic-tac-toe game
- 001 tic-tac-toe game
- uva 11623 - Tic Tac Toe(game)
- Tic-Tac-Toe
- spring-mvc数据源配置及modelAttribute注解
- 数据科学工程师面试宝典系列之四---MySQL基础
- 如何编译生成dll文件以及如何调用dll文件
- SpringBoot10 之 定时器
- Linux下实时查看tomcat运行日志
- 754B Ilya and tic-tac-toe game
- Hadoop集群(第9期)_MapReduce初级案例
- 每天一个linux命令:watch命令
- SpringBoot11 之Druid连接池
- GestureDetector手势监听Demo
- Java设计模式(观察者模式)
- VirtualBox环境下Debian安装增强工具失败
- 关于apache配置阿里云证书https的步骤(详细)
- 求最大公约数代码