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中间恰好有一个 ...
随机推荐
- firefox插件HTTP-Tool的使用方法
2016年11月3日 14:32:01 星期四 chrome 有postman很强大 我比较懒, 不想FQ, 经常用firefox, 试了几款模拟post请求的插件, 觉得http-tool挺简洁的 ...
- ProtocolBuffers-3 For Objective C (1)-简单的使用
一. 介绍 Protocolbuffer 是一种数据交换格式,类似于我们现在使用的XML和JSON.是Google公司推出的,本来这个语言是Google公司内部使用的,随着Google对这个格式的优化 ...
- RakNet基本教程
官方网址:http://www.jenkinssoftware.com/raknet/manual/tutorialsample3.html Tutorial code sample 3 Remote ...
- centos7.0 下安装git(ssh方式)
最近刚弄了个阿里云,在上面弄个git服务器,这里只弄了ssh方式访问,http方式访问的可以看我另外一个随笔http://www.cnblogs.com/hz-cww/p/6077970.html. ...
- Android版本与api Level
Platform Version API Level VERSION_CODE Notes Android 4.4 19 KITKAT Platform Highlights Android 4.3 ...
- Android 笔记 Intent and Bundle day7
学习了Intent与Bundle的使用,进行应用中的交互 package com.example.intent; import android.app.Activity; import android ...
- 设计模式 之 原型模式(ProtoType)
什么时原型模式 或 原型模式的定义: 用原型实例来指定创建对象的种类,并通过拷贝这些原型创建新的对象. 原型模式的特点: 1),它是面向接口编程, 2),原型模式的新对象是对原型实例的一个克隆 ...
- js控制刷新后回到页面原来位置
1.document.location.reload(); 2.http://www.jb51.net/article/99749.htm
- Python 判断变量的类型
这里有两种方法.type 和isinstance import types aaa = 0 print type(aaa) if type(aaa) is types.IntType: print & ...
- strip_tags、htmlspeciachars
strip_tags:过滤html.xml标签: htmlspecialchars:把预定义自负转化为html实体:包括<.>.'.".& sql注入:将'." ...