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 ...
随机推荐
- VRP
VRP系统命令采用分级保护方式,命令被划分为参观级.监控级.配置级.管理级4个级别. 参观级:网络诊断工具命令(ping.tracert).从本设备出发访问外部设备的命令(包括:Telnet客户端.S ...
- 【接口测试】Jenkins+Ant+Jmeter搭建持续集成的接口测试平台
参考文档: http://www.cnblogs.com/liuqi/p/5224579.html
- AngularJS: 'Template for directive must have exactly one root element' when using 'th' tag in directive template
.controller('HomeController', function($scope,$location) { $scope.userName='天下大势,为我所控!'; $scope.clkU ...
- 基于天天动听API开发在线音乐查询网站
预览图 源码下载 地址:https://github.com/bajdcc/dev/tree/master/ttpod 文件夹说明: App_Code,WCF服务 Script,离线下载的celery ...
- 读<jQuery 权威指南>[5]-插件
一.说明 jQuery插件官网:http://plugins.jquery.com/ 使用插件时引用顺序:插件引用要位于主jquery库之后. 二.插件应用实例 演示插件jquery.validate ...
- 将excel2003文档文件转换为excel2007格式
在sharepoint 2010 中,excel2007或excel 2010文档格式,支持web app 应用,能够在浏览器在线打开,查看,但excel 2003格式的文档只能用office客户端打 ...
- Xceed Ultimate Suite Xceed界面控件套包下载
Xceed Ultimate Suites是一款用户界面.数据处理套包,从.NET/WPF/silverLight平台到ActiveX下包含了65个子控件,以及Xceed公司的所有控件,具有表格.风格 ...
- 获取本地soapUI项目路径
def projectDir = ${projectDir}
- 利用GCC编译器生成动态链接库和静态链接库
转载请标明:http://www.cnblogs.com/winifred-tang94/ 1.编译过程 gcc –fPIC –c xxx.c 其中-fPIC是通知gcc编译器产生位置独立的目标代码. ...
- Enable SSHD on Ubuntu
https://help.ubuntu.com/community/SSH/OpenSSH/Configuring