LeetCode "Design Tic-Tac-Toe"
We don't have to keep a complete chess board.. just counters!
class TicTacToe {
vector<int> cntVer;
vector<int> cntHor;
int cntDiag0;
int cntDiag1;
int _n;
public:
/** Initialize your data structure here. */
TicTacToe(int n) {
cntVer.assign(n, );
cntHor.assign(n, );
cntDiag0 = cntDiag1 = ;
_n = n;
}
/** Player {player} makes a move at ({row}, {col}).
@param row The row of the board.
@param col The column of the board.
@param player The player, can be either 1 or 2.
@return The current winning condition, can be either:
0: No one wins.
1: Player 1 wins.
2: Player 2 wins. */
int move(int row, int col, int player)
{
int d = player == ? : -;
cntVer[col] += d;
if(abs(cntVer[col]) == _n) return player;
cntHor[row] += d;
if(abs(cntHor[row]) == _n) return player;
if(col== row)
{
cntDiag0 += d;
if(abs(cntDiag0) == _n) return player;
}
if ((col + row) == _n - )
{
cntDiag1 += d;
if(abs(cntDiag1) == _n) return player;
}
return ;
}
};
LeetCode "Design Tic-Tac-Toe"的更多相关文章
- 【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 ...
- 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= ...
- 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 ...
- LeetCode 5275. 找出井字棋的获胜者 Find Winner on a Tic Tac Toe Game
地址 https://www.acwing.com/solution/LeetCode/content/6670/ 题目描述A 和 B 在一个 3 x 3 的网格上玩井字棋. 井字棋游戏的规则如下: ...
- [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] Design Tic-Tac-Toe 设计井字棋游戏
Design a Tic-tac-toe game that is played between two players on a n x n grid. You may assume the fol ...
随机推荐
- fis3运行项目的前准备
前几天搭建了fis3环境,但是不会运行项目.因为刚来公司前辈把项目打包给我,但是我之前没有做过这种项目. 今天前辈来了,教我几个命令行运行项目.但是没有成功..... 原因我的sass是单独安装的,没 ...
- 编程之美----NIM游戏
: 博弈游戏·Nim游戏 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 今天我们要认识一对新朋友,Alice与Bob.Alice与Bob总是在进行各种各样的比试,今天他 ...
- svn用法:摘自http://wh-vip-126-com200907043220.iteye.com/blog/424642
下载最新版本svn(http://www.visualsvn.com/server/ ) 1.安装SVN 2.创建user与repository 3.Eclipse下配置SVN插件 3.1帮助- ...
- shell变量赋值 不能有空格的原因
典型例子: a=date echo $a 成立 a =date echo $a 不成立 其实原因很简单 shell在解释命令时的原则是第一个符号标记只能是程序或者命令,有空格的时候第 ...
- iOS开发UI篇—直接使用UITableView Controller
iOS开发UI篇—直接使用UITableView Controller 一.一般过程 // // YYViewController.h // UITableView Controller // // ...
- 从0到1---“保多多”APP的开发(一)
2015年8月份,我正式接手了公司保多多APP的开发(和另一个同事一起). 我之前并没有过从0开始创建一款APP,这次能有这样的机会,实在让我感到兴奋.因为我相信,作为这款APP的主要开发人员,在这一 ...
- 单例模式(Singleton Pattern)
动机: 在软件系统中,经常有这样一些特殊的类,必须保证它们在系统中只存在一个实例,才能确保它们的逻辑正确性.以及良好的效率. 如何绕过常规的构造器,提供一种机制来保证一个类只有一个实例? 这应该是类设 ...
- 学会使用Constant常量或者Enum枚举
好多时候我们在数据库表中存放的类型是一个代号CHAR(1) 0,1,2,3等分别代表些什么. 那么你是怎么知道0,1,2,3代表什么的呢? 有的是建表,连接查询,但很少人用. 有的是在jsp页面c:i ...
- C#获取字符首字母
///<summary> /// 获取字符首字母 /// </summary> public static string GetPyChar(string c) { if (s ...
- 安卓手机上的python运行环境-qpython
qpython是一个能让安卓手机运行和编写python的APP,到网上下载APK安装或者在GOOGLE PLAY搜索安装即可. 安装之后你可以你手机跑自己的python程序. qpython有两个大版 ...