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 ...
随机推荐
- Java基础知识强化之集合框架笔记32:集合之可变参数的概述和使用
1. 可变参数的概述和使用: (1)可变参数:定义方法的时候不知道该定义多少个参数(2)格式: 修饰符 返回值类型 方法名(数据类型… 变量名){ } 注意: 这里的变量其实是一个数 ...
- asp.net对word文档进行修改 对于使用word文档做模板编辑比较适用
最近做项目,需要多word文档进行编辑并导出一个新的word,在最初的word编辑中留下特定的字符串用来替换,然后在本地生成一个新的word文档,并且不修改服务器中的word文档,这样才能保证服务器中 ...
- CentOS 5.4下的Memcache安装步骤(Linux+Nginx+PHP+Memcached)
原文链接:http://www.jb51.net/article/29668.htm
- struts2中方法拦截器(Interceptor)的中的excludeMethods与includeMethods的理解
http://www.cnblogs.com/langtianya/archive/2013/04/10/3012205.html
- 数据库导出导入操作(expdp,impdp)
EXPDP和IMPDP是服务端的工具程序,他们只能在ORACLE服务端使用,不能在客户端使用. 命令行: sqlplus/nolog connect username/password as sysd ...
- 解决NSAttributedString与UILabel高度自适应计算问题
两个类扩展方法: /** * 修改富文本的颜色 * * @param str 要改变的string * @param color 设置颜色 * @param range 设置颜色的文字范围 ...
- Objective-C中的分类与协议
分类 在谈分类之前,我们可以先探究下,OC中为什么出现分类这种机制,有什么好处? 假设你接到一个大项目:计算两个整数的和,差.接到任务的你马上动手.编写代码如下: #import <Founda ...
- 安卓开发之viewpager学习(头条显示)
activity_luancher.xml代码如下: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res ...
- cmd 命令行下复制、粘贴的快捷键
1.单击左下角“开始”菜单,选择“运行”,输入“cmd”. 2.在弹出的cmd窗口的标题栏上点击“右键”,选择“属性”. 3.在弹出的对话框中选择“选项”这个选项卡,在“编辑选项”区域中勾选“快速编辑 ...
- php学习小技巧
1.print_r可打印数组 <?php echo '<p class="ajax">This paragraph was loaded with AJAX.&l ...