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中间恰好有一个 ...
随机推荐
- [PHP][REDIS]phpredis 'RedisException' with message 'read error on connection'
最近一个后台常驻job通过redis的brpop阻塞读取消息时,设置了永不超时 while( $re=$redis->brPop($queue_name,0) ){ } 但是在实际的使用中发现很 ...
- Winform的"透明"
手头目前的一个项目(.Net4.0)中有这样一个需求:在程序中要进行视频采集,并且要在视频影像区域进行绘图编辑,对绘图能进行拉伸,拖拽和删除.从需求来看,必须得在视频影像区的上方盖一层画布才能这么操作 ...
- JDBC的操作总结
JDBC 操作总结 JDBC是一组能够执行SQL语句的API JDBC的操作方式比较单一,简单的分为以下几个流程: 1.通过数据库厂商提供的JDB类库想DriverManager注册数据库驱动 ...
- Css样式表【边界边框】【列表方块】
一.如何给div加边框?[边界边框] 我们先做一个整个边框,并附加成绿色的边框. ①使用属性border进行设置. →→ ②也可以单独更改某个边的边框线的颜色,利用border属性更改. 如果将div ...
- android Sqlite小记
1.android.database.sqlite.SQLiteException: near "": syntax error (code 1): 语法错误,如果你的报了这个错误 ...
- Delphi中ExtractFilePath、ParamStr以及更多文件/目录操作涉及的函数。附加对应的例子
先介绍ExtractFilePath和ParamStr ParamStr 该函数的原型是:function paramstr(i: Integer): String; 对于任何的application ...
- 【Java EE 学习 72 上】【数据采集系统第四天】【增加调查logo】【文件上传】【动态错误页指定】【上传限制】【国际化】
增加logo的技术点:文件上传,国际化 文件上传的功能在struts2中是使用文件上传拦截器完成的. 1.首先需要在页面上添加一个文件上传的超链接. 点击该超链接能够跳转到文件上传页面.我给该表单页面 ...
- postgresql 常用数据库命令
连接数据库, 默认的用户和数据库是postgrespsql -U user -d dbname 切换数据库,相当于MySQL的use dbname\c dbname列举数据库,相当于mysql的sho ...
- 【leetcode】Minimum Depth of Binary Tree
题目简述: Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along th ...
- python urllib
在伴随学习爬虫的过程中学习了解的一些基础库和方法总结扩展 1. urllib 在urllib.request module中定义下面的一些方法 urllib.request.urlopen(url,d ...