3C Tic-tac-toe
题目大意:
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cstdlib>
using namespace std;
typedef __int64 LL;
const LL INF = 0xffffff;
const int maxn = ;
const LL MOD = 1e9+;
#define Illegal 0 ///判断这个局面不合法
#define First 1 ///该第一个人了
#define Second 2 ///该第二个人了
#define Draw 3 ///平局
#define Tfpw 4 ///这个局面刚出来F就赢了
#define Tspw 5 ///这个局面刚出来S就赢了
char maps[][]; bool Ok(int x,int y)
{
return x>= && x< && y>= && y < ;
} bool Win(char ch)
{
for(int i=; i<; i++)
{
if(maps[][i] == ch && maps[][i] == ch && maps[][i] == ch)
return true;
if(maps[i][] == ch && maps[i][] == ch && maps[i][] == ch)
return true;
}
if(maps[][] == ch && maps[][] == ch && maps[][] == ch)
return true;
if(maps[][] == ch && maps[][] == ch && maps[][] == ch)
return true;
return false;
} int solve()
{
int numX = , num0 = ;
for(int i=; i<; i++)
for(int j=; j<; j++)
{
if(maps[i][j] == 'X')
numX ++;
if(maps[i][j] == '')
num0 ++;
}
if( !(numX - num0 == || numX - num0 == ) || (Win('X') && Win('') ) || (Win('X') && numX - num0 != ) || (Win('') && numX - num0 != ))
return Illegal;
if(Win('X'))
return Tfpw;
if(Win('') && numX - num0 == )
return Tspw;
if(num0 == && numX == )
return Draw;
if(numX - num0 == )
return First;
if(numX - num0 == )
return Second; return ;
} int main()
{
for(int i=; i<; i++)
scanf("%s", maps[i]); int ans = solve(); if(ans == Illegal)
puts("illegal");
else if(ans == First)
puts("first");
else if(ans == Draw)
puts("draw");
else if(ans == Second)
puts("second");
else if(ans == Tfpw)
puts("the first player won");
else if(ans == Tspw)
puts("the second player won"); return ;
}
3C 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 ...
- 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( ...
- LeetCode 5275. 找出井字棋的获胜者 Find Winner on a Tic Tac Toe Game
地址 https://www.acwing.com/solution/LeetCode/content/6670/ 题目描述A 和 B 在一个 3 x 3 的网格上玩井字棋. 井字棋游戏的规则如下: ...
- 【Python五篇慢慢弹】数据结构看python
数据结构看python 作者:白宁超 2016年10月9日14:04:47 摘要:继<快速上手学python>一文之后,笔者又将python官方文档认真学习下.官方给出的pythondoc ...
随机推荐
- Python的Ftplib问题:UnicodeEncodeError: 'latin-1' codec can't encode characters的解决方法
ftplib中有一个方法是cwd,用来切换目录,需要传入一个dirname,经过个人测试,该dirname不能含有汉字,会抛出:UnicodeEncodeError: 'latin-1' codec ...
- 关于黑名单IP的设置
最近在做一个项目的时候,需要做一个自动的黑名单设置,也就是将一天内重复出错的超过一定次数的手机号,和IP给加入黑名单里面,下次请求的时候先判断是否在黑名单里. 这个是获取IP地址的方法 private ...
- sql根据'/'截取最后的字符串
filpath字段值:/DataFile/UpLoad/Logo/NoPhoto.jpg select filpath,REVERSE((SUBSTRING(REVERSE(FilPath),0,CH ...
- HTML5 WebAudioAPI(三)--绘制频谱图
HTML <style> #canvas { background: black; } </style> <div class="container" ...
- [原创] SQLite数据库使用清单(下)
上文两章对SQLite的功能.语法.和操作进行了介绍,本文讲解SQLite的一些高级语法和操作. 3.
- ZBar Installer
ZBar Install.For windows:http://sourceforge.net/projects/zbar/files/zbar/0.10/zbar-0.10-setup.exe/do ...
- JavaMail API 1.4.7邮件发送
下载oracle javaMail API: http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive- ...
- Java学习----对象间的继承
继承:子类可以使用父类非私有的成员变量和方法 public class Father { public String name; public String bloodType; private in ...
- 基于jQuery查找dom的多种方式性能问题
这个问题的产生由于我们前端组每个人的编码习惯的差异,最主要的还是因为代码的维护性问题.在此基础上,我对jQuery源码(1.11.3)查找dom节点相关的内容进行了仔细的查阅,虽然并不能理解的很深入 ...
- 参数计数不匹配,未处理System.Reflection.TargetParameterCountException
系统出现异常:参数计数不匹配,未处理System.Reflection.TargetParameterCountException, 系统会显示如下的异常信息,但异常信息往往与实际异常位置差十万八千量 ...