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 ...
随机推荐
- VMware克隆后,网卡若干问题
网卡问题 由于克隆虚拟机,vmware只是修改了虚拟机的名字等信息,并没有修改虚拟硬盘中的任何信息, 导致克隆后网卡的MAC地址和操作系统中记录的mac地址不符,导致eth0启动不起来. 操作系统记录 ...
- 请尝试使用 Console.Read。错误原因
当出现错误: 如果应用程序没有控制台或控制台输入已通过文件进行了重定向,则无法读取键.请尝试使用 Console.Read. 一定是在非控制台应用程序中用了Console.ReadKey(); Con ...
- c#连接各种数据库
1.C#连接连接Access程序代码: ------------------------------------------------------------------------------- ...
- enmo_day_02
Secure CRT, putty, 等终端工具 DML :u, d, i, m 增,删,改,合并 DDL : DCL : DQL : 数据字典 :存放在数据文件中,SYSTEM表空间里,纪录数据的变 ...
- [安卓]应用程序资源(App Resources)
谷歌推荐我们,在开发安卓系统应用程序的时候,要把资源从代码中分离出来,这样便于我们单独维护它们.采取分离的资源设计,我们还可以提供可选资源,支持特定的设备配置譬如不同的语言或屏幕尺寸,随着越来越多的A ...
- 使用PHPUnit + Selenium进行自动化测试
project: blog target: how-to-use-phpunit-selenium-test.md date: 2015-12-22 status: publish tags: - S ...
- Linux kernel map
- C语言之EOF和feof()
EOF用于判断所操作的文件是否已经读到文件结束,是在stdio.h文件中定义的符号常量,值为-1. 即当系统读取到文件结尾,所返回的一个信号值(也就是-1). EOF不是可输出字符,因此不能在屏幕上输 ...
- Android ViewPager Fragment使用懒加载提升性能
Android ViewPager Fragment使用懒加载提升性能 Fragment在如今的Android开发中越来越普遍,但是当ViewPager结合Fragment时候,由于Androi ...
- 1、webservice的简单使用
1.新建一个web端项目 2.点击添加项,选择web服务 3.在已经建好的项目中写一个方法 4.发布(发布方法选文件系统,web需要管理员权限) 生成文件夹: 5.配置IIS(略) 6.调用webse ...