POJ 2361 Tic Tac Toe
题目:给定一个3*3的矩阵,是一个井字过三关游戏。开始为X先走,问你这个是不是一个合法的游戏。也就是,现在这种情况,能不能出现。如果有人赢了,那应该立即停止。那么可以知道X的步数和O的步数应该满足x==o+1或者x==o
这种情况是允许的,
这种情况是O赢。(x==o)
这种情况是X赢(x==o+1)。那么就可以知道
如果
①、如果x>o+1(步数过多)||o>x(不符合x先行的规矩) printf("no\n");
②、如果是x赢了win(x)但是x!=o+1 不行
③、如果是O赢了win(o)但是x!=o 不行
④、两个同时赢了 不行, 但是这个和上面的重合了的,上面判断了要么O赢要么X赢,然而步数也只有x==o或者x==o+1两种,那么必然会进入其中一个判断那里(前提是你判断的win(x)和win(o)都是赢)。那么就可以不用判断啦
这里我学习到别人的代码判断是否赢win(x) 思路非常不错。学习了。。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std;
#define inf 1<<28
#define MAX(x,y) ((x)>(y)?(x):(y))
#define MIN(x,y) ((x)>(y)?(y):(x))
#define MID(x,y) (MAX(x,y)-((MAX(x,y)-MIN(x,y))>>1))
#define istwopow(x) ((x&(x-1))==0)
#define LL __int64 #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
int win (char ch,char str[][])
{
for (int i=;i<=;i++)
{
for (int j=;j<=&&str[i][j]==ch;j++)
{
if (j==) return ;
}//行
for (int j=;j<=&&str[j][i]==ch;j++)
{
if (j==) return ;//列
}
}
if (str[][]==ch&&str[][]==ch&&str[][]==ch)
{
return ;
}
else if (str[][]==ch&&str[][]==ch&&str[][]==ch)
{
return ;
}
return ;
}
void work ()
{
char str[][];
for (int i=;i<=;i++)
{
scanf ("%s",str[i]+);
}
int x=,o=;
for (int i=;i<=;i++)
{
for (int j=;j<=;j++)
{
x += str[i][j]=='X';
o += str[i][j]=='O';
}
}
if (o>x||x>o+)//步数不符合
{
printf ("no\n");
return ;
}
char ch1='X';
char ch2='O';
if (win(ch2,str)&&o!=x)//o赢应该步数相等
{
printf ("no\n");
return ;
}
if (win(ch1,str)&&x!=o+)//x赢应该步数x==o+1
{
printf ("no\n");
return ;
}
printf ("yes\n");
return ;
}
int main ()
{
freopen("data.txt","r",stdin);
int t;
scanf ("%d",&t);
while (t--)
{
work ();
}
return ;
}
Your job is to read a grid and to determine whether or not it could possibly be part of a valid Tic Tac Toe game. That is, is there a series of plays that can yield this grid somewhere between the start and end of the game?
你的任务是读入棋盘状态,问可不可能是一个有效的三子棋棋盘,也就是说是否存在一系列走棋,能到达该棋盘状态。
POJ 2361 Tic Tac Toe的更多相关文章
- 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 ...
- 【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( ...
- LeetCode 5275. 找出井字棋的获胜者 Find Winner on a Tic Tac Toe Game
地址 https://www.acwing.com/solution/LeetCode/content/6670/ 题目描述A 和 B 在一个 3 x 3 的网格上玩井字棋. 井字棋游戏的规则如下: ...
- HOJ题目分类
各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...
随机推荐
- xml schema 中如何定义类似Map的结构
利用xs:unique关键字.在xs:element里添加unique节点,任意命名,然后用xs:selector来选择需要唯一的域, xs:field 里指定特定的字段. 例如:定义所有Item里的 ...
- Poj 2403 Hay Points(Map)
一.题目大意 实现一个工资计算系统.工资的计算规则是:首先,给定一些关键字和对应的价值,这个相对于字典.然后给出的是求职者的描述,如果这个描述中包含关键字则加上对应的价值,总得价值就是这个求职者的工资 ...
- 【转】 Pro Android学习笔记(六四):安全和权限(1):签发apk
目录(?)[-] Android安全模型 数字证书签发 Debug的keystore 生产unsigned的apk 为apk进行证书签发 align安装包 使用Export Wizard生成签发的ap ...
- 前端框架:template
ylbtech-前端框架: 1.返回顶部 2.返回顶部 3.返回顶部 4.返回顶部 5.返回顶部 6.返回顶部 作者:ylbtech出处:http://ylbtech.cn ...
- Java类的生命周期(转)
引言 最近有位细心的朋友在阅读笔者的文章时,对java类的生命周期问题有一些疑惑,笔者打开百度搜了一下相关的问题,看到网上的资料很少有把这个问题讲明白的,主要是因为目前国内java方面的教材大多只是告 ...
- 超牛 猴子补丁,修改python内置的print
猴子补丁一般是用于修改三方包或官方包,也可以用来修改自己或者他人的代码. 但也可以用来修改python 语言内置的关键字. 本篇博客修改python最常用的内置print,使你使用print时候,自动 ...
- python version 2.7 required,which was not found in
python version 2.7 required,which was not found in 出现上面这种情况的原因我推测有两种: 1.NumPy和SciPy官方网站上只提供了32bit的文件 ...
- Linq to Object之非延迟标准查询操作符
非延时标准查询操作符是指不具备延时查询特性的标准查询操作符,这些操作符一般用于辅助延时标准查询操作符使用. 1.ToArray操作符 ToArray操作符用于将一个输入序列转换成一个数组. 方法原型: ...
- ffmpeg+HLS实现直播与回放
Nginx配置视频服务器 server { listen ; server_name localhost; location /hls{ add_header Access-Control-Allow ...
- [poj1459]Power Network(多源多汇最大流)
题目大意:一个网络,一共$n$个节点,$m$条边,$np$个发电站,$nc$个用户,$n-np-nc$个调度器,每条边有一个容量,每个发电站有一个最大负载,每一个用户也有一个最大接受量.问最多能供给多 ...