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 ...
随机推荐
- Git基础操作
配置秘钥 1.检查本机有没有秘钥 检查~/.ssh看看是否有名为d_rsa.pub和id_dsa.pub的2个文件. $ ~/.sshbash: /c/Users/lenovo/.ssh: Is a ...
- 使用QTP测试Web对象
加载Web插件先启动QTP,再启动浏览器,否则Web元素识别不了最新版本QTP11支持的浏览器:IE:6.7.8Firefox:3.0.x.3.5.QTP支持直接访问DOM(Document Obje ...
- 关于ecshop的那些故事
1.php下foreach()错误提示Warning: Invalid argument supplied for foreach() 错误提示:Warning: Invalid argument s ...
- E:Sudoku
总时间限制: 2000ms 内存限制: 65536kB描述Sudoku is a very simple task. A square table with 9 rows and 9 columns ...
- IIS7配置asp网站
An error occurred on the server when processing the URL. Please contact the system administrator. If ...
- touch id 开发
min platform : 8.0 #import <LocalAuthentication/LocalAuthentication.h> LAContext *context = [[ ...
- NSURLCache 和 NSCache 的区别
NSURLCache 和 NSCache 的区别 NSURLCache提供的是URL Request缓存,可以在Memory和Disk上:NSCache提供了HTTP Request外的东西的缓存方式 ...
- 新手入门之GDB调试
写这篇文章算是对最近两天工作的一个经验总结吧. 要让可执行文件比较方便地在DGB上调试,在用gcc编译的时候要使用-g选项. 如何使用GDB启动被调试程序? "gdb path_to_deb ...
- jQuery侧边栏固定
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- (转)PhoneGap开发环境搭建
(原)http://www.cnblogs.com/Random/archive/2011/12/28/2305398.html PhoneGap开发环境搭建 项目中要用PhoneGap开发,了解 ...