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( ...
随机推荐
- AJPFX关于hashmap和hashtable 的区别
Hashtable和HashMap类有三个重要的不同之处.第一个不同主要是历史原因.Hashtable是基于陈旧的Dictionary类的,HashMap是Java 1.2引进的Map接口的一个实现. ...
- 【学习笔记】深入理解js原型和闭包(7)——原型的灵活性
在Java和C#中,你可以简单的理解class是一个模子,对象就是被这个模子压出来的一批一批月饼(中秋节刚过完).压个啥样,就得是个啥样,不能随便动,动一动就坏了. 而在javascript中,就没有 ...
- php 生成饼状图,折线图,条形图 通用类
生成饼状图,折线图,条形图通用的php类,这里使用的是百度 Echart. Echart 官方网站 http://echarts.baidu.com/ <?php class Echarts ...
- Github-Client(ANDROID)开源之旅(三) ------ 巧用ViewPagerIndicator
接上篇博文:Github-Client(ANDROID)开源之旅(二) ------ 浅析ActionBarSherkLock 文中结合了网易新闻客户端讲解了开源库ActionBarSherklock ...
- windows 下防火墙安全加固,配置规则
netsh advfirewall firewall: 显示关于防火墙操作的常见命令的帮助信息 netsh advfirewall firewall show rule name=all dir=in ...
- Codeforces Gym 2015 ACM Arabella Collegiate Programming Contest(二月十日训练赛)
A(By talker): 题意分析:以a(int) op b(int)形式给出两个整数和操作符, 求两个整数是否存在操作符所给定的关系 ,有则输出true,无则输出false: 思路:由于无时间复杂 ...
- 原生ajax请求的五个步骤
//第一步,创建XMLHttpRequest对象 var xmlHttp = new XMLHttpRequest(); function CommentAll() { //第二步,注册回调函数 xm ...
- qobject_cast
void QLadderDiagramItem::GetMainForm(DoType sourceType){ for each (QWidget *w in qApp->topLevelWi ...
- Activiti6简明教程
一.为什么选择Activiti 工作流引擎对比 二.核心7大接口.28张表 7大接口 (一)7大接口 RepositoryService:提供一系列管理流程部署和流程定义的API. RuntimeSe ...
- 有n个整数,使其前面各数顺序向后移n-m个位置,最后m个数变成最前面的m个数
题目:有n个整数,使其前面各数顺序向后移n-m个位置,最后m个数变成最前面的m个数 public class 第三十六题数组向后移m个位置 { public static void main(Stri ...