CodeForces - 754B Ilya and tic-tac-toe game
简单搜索
判断是否能在最后一步下棋得到胜利
问题转化为 是否有可以胜利的x的摆法
那么就只有两种情况
1、有两个x相连 并且 在端点还有.可以落子 那么就可以在最后一步 胜利
2、两个x中间恰好有一个.空着 那么可以再这里落子胜利
搜索这两种情况 存在则胜利 不存在 则无法再最后一步胜利
#include <iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <map>
#include <queue>
#include <fstream>
#define READ() freopen("in.txt", "r", stdin);
using namespace std; typedef pair<int,int> P; char maze[][];
struct Point
{
int x, y;
}point[];
int num = ;
int d[][] = {-, , -, , , , , , , , , -, , -, -, -};
bool vis[][];
bool OK(int x, int y)
{
if (x < || x >= || y < || y >= ) return false;
return true;
}
bool Search()
{ queue<P> que;
for (int i = ; i < num; i++)
{
que.push(P(point[i].x, point[i].y));
}
// memset(vis, 0, sizeof(vis));
while (!que.empty())
{
P p = que.front();
que.pop();
// if(vis[p.first][p.second]) continue;
// vis[p.first][p.second] = true;
//假设是作为端点 的点
for (int i = ; i < ; i++)
{
int nx = p.first+d[i][], ny = p.second+d[i][];
if (!OK(nx, ny)) continue;
if (maze[nx][ny] == 'x')
{
nx += d[i][];
ny += d[i][];
if (!OK(nx, ny)) continue;
if (maze[nx][ny] == 'x')
{
return true;
}
}
}
//假设是作为中间的点
for (int i = ; i < ; i++)
{
int nx = p.first+d[i][], ny = p.second+d[i][];
if (!OK(nx, ny)) continue;
if (maze[nx][ny] == 'x')
{
nx = p.first-d[i][], ny = p.second-d[i][];
if (!OK[nx][ny]) continue;
if (maze[nx][ny] == 'x')
{
return true;
}
}
}
}
return false; }
int main()
{
READ()
for (int i = ; i < ; i++)
{
for (int j = ; j < ; j++)
{
scanf("%c", &maze[i][j]);
if (maze[i][j] == '.')
{
point[num].x = i;
point[num].y = j;
num++;
}
}
getchar();
}
if (Search()) cout << "YES" << endl;
else cout << "NO" << endl;
}
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 ...
- bfs codeforces 754B Ilya and tic-tac-toe game
这题简直把我坑死了 所有的坑都被我中了 题意: 思路:bfs or 模拟 模拟似乎没有什么坑 但是bfs真的是坑 AC代码: #include "iostream" #includ ...
- [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( ...
随机推荐
- new几种用法
在 C# 中,new 关键字可用作运算符.修饰符或约束. new 运算符 用于创建对象和调用构造函数. new 修饰符 用于向基类成员隐藏继承成员. new 约束 用于在泛型声明中约束可能用作类型参数 ...
- Node.Js的Module System 以及一些常用 Module
Node.Js学习就按照这本书的流程来. 在第7章结束与第10章结束时分别自己出一个小项目练练手.Node.Js的入门学习计划是这样. 目录:, QQ:1045642972 欢迎来索书以及讨论Node ...
- Spring-bean(二)
命名空间 自动装配 bean之间的关系:继承:依赖 使用外部属性文件 SpEL bean的生命周期 bean的后置处理器 (一)util命名空间 当用list,set等集合时,不能将集合作为独立的be ...
- linux下自定义pid实现任意数据采集
当你需要采集特殊的数据,而不满足于现有的你所知的数据模版时,自定义oid将是你必须而且非常好的解决方式. oid是snmp服务器为每条系统信息提供的唯一标识符,如果不能很好理解snmp服务的话,可以将 ...
- 洛谷 P1955 程序自动分析
题目描述 在实现程序自动分析的过程中,常常需要判定一些约束条件是否能被同时满足. 考虑一个约束满足问题的简化版本:假设x1,x2,x3...代表程序中出现的变量,给定n个形如xi=xj或xi≠xj的变 ...
- IOS中经典的缓存对比
http://bpoplauschi.wordpress.com/2014/03/21/ios-image-caching-sdwebimage-vs-fastimage/
- java环境变量配置-简易菜鸟版
NO1:Path配置: 用户Path:%JAVA_HOME%\bin 系统Path:%java_home%\bin;%java_home%\jre\bin NO2:CLASSPATH配置: .;%ja ...
- Android(java)学习笔记169:服务(service)之为什么使用服务
1.服务 service 长期在后台运行的进程,一般没有应用程序界面 2.进程线程和应用程序之间的关系 应用程序开启,系统启动一个Linux进程,所有的组件都是运行在同一个进程的同一个线程(mai ...
- c语言 错误记录
1.预处理错误 #include <> //系统内部的 #include "" // 自定义的 遇到 not find------解决方案:gcc -I 跟查找 ...
- 联玛客(T 面试)
我看你写的项目都是SSM架构,那我们就来聊下Spring 1.Spring的生命周期,与生命周期相关的事件? 2.阿里巴巴开发手册中的规范有哪些? 切到了异常捕捉话题 3.线程你有了解吗? 创建线程的 ...