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 ...
随机推荐
- HTML简单介绍及常见元素
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- mysql隐藏文件一定要删除彻底
之前部署自己的服务器机器的时候 机器的mysql密码是不知道的.彻底删除了软件之后还是解决不了问题,而且我把MYSQL在C盘的隐藏文件也给删除了.但是还是不行 最后我偶然发现一个方法去找隐藏问题.我之 ...
- android 定时请求(两种实现方式)
方式一: Handler + Runnable (借鉴网址:http://stackoverflow.com/questions/6207362/how-to-run-an-async-task-fo ...
- EntityFrameowk6.1 使用enum和低版本的不同
原有项目中使用EF5.0 实体类 public partial class Log : BaseEntity { public Nullable<int> LogLevelId { get ...
- TSQL Beginners Challenge 1 - Find the second highest salary for each department
很久以前准备写的系列文章,后来因为懒一直耽搁着,今天突然决定继续下去,于是有了这篇文章,很基础,但很常用.题目描述依然拷贝.简单来说就是找出个个部门薪水排名第二的人,排名相同的要一起列出来. Intr ...
- 【转】iOS开发网络篇—发送json数据给服务器以及多值参数
原文: http://www.cnblogs.com/wendingding/p/3950132.html 一.发送JSON数据给服务器 发送JSON数据给服务器的步骤: (1)一定要使用POST请求 ...
- WebSocket基于javaweb+tomcat的简易demo程序
由于项目需要,前端向后台发起请求后,后台需要分成多个步骤进行相关操作,而且不能确定各步骤完成所需要的时间 倘若使用ajax重复访问后台以获取实时数据,显然不合适,无论是对客户端,还是服务端的资源很是浪 ...
- dedecms 常用标签调用
/*------------------单个ip调用-------------------*/ {dede:type typeid="12"} <a title=" ...
- wdcp-apache配置错误导致进程淤积进而内存吃紧
内存总是越来越少,虚拟内存使用越来越多 首先确定到底是什么占用了大量的内存 可以看到,大部分内存被闲置的httpd进程占用 且当我重启mysql服务后,内存没有出现明显变化,但是当我重启apache时 ...
- To Build A Dev Env On Linux(Ubuntu)
Step1:System Installing 1)use iso image to Step2:Configuration Step3:Software Installing Step4:Other ...