We don't have to keep a complete chess board.. just counters!

  1. class TicTacToe {
  2. vector<int> cntVer;
  3. vector<int> cntHor;
  4. int cntDiag0;
  5. int cntDiag1;
  6. int _n;
  7. public:
  8. /** Initialize your data structure here. */
  9. TicTacToe(int n) {
  10. cntVer.assign(n, );
  11. cntHor.assign(n, );
  12. cntDiag0 = cntDiag1 = ;
  13. _n = n;
  14. }
  15.  
  16. /** Player {player} makes a move at ({row}, {col}).
  17. @param row The row of the board.
  18. @param col The column of the board.
  19. @param player The player, can be either 1 or 2.
  20. @return The current winning condition, can be either:
  21. 0: No one wins.
  22. 1: Player 1 wins.
  23. 2: Player 2 wins. */
  24. int move(int row, int col, int player)
  25. {
  26. int d = player == ? : -;
  27.  
  28. cntVer[col] += d;
  29. if(abs(cntVer[col]) == _n) return player;
  30.  
  31. cntHor[row] += d;
  32. if(abs(cntHor[row]) == _n) return player;
  33.  
  34. if(col== row)
  35. {
  36. cntDiag0 += d;
  37. if(abs(cntDiag0) == _n) return player;
  38. }
  39. if ((col + row) == _n - )
  40. {
  41. cntDiag1 += d;
  42. if(abs(cntDiag1) == _n) return player;
  43. }
  44.  
  45. return ;
  46. }
  47. };

LeetCode "Design Tic-Tac-Toe"的更多相关文章

  1. 【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 ...

  2. 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 ...

  3. POJ 2361 Tic Tac Toe

    题目:给定一个3*3的矩阵,是一个井字过三关游戏.开始为X先走,问你这个是不是一个合法的游戏.也就是,现在这种情况,能不能出现.如果有人赢了,那应该立即停止.那么可以知道X的步数和O的步数应该满足x= ...

  4. 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 ...

  5. LeetCode 5275. 找出井字棋的获胜者 Find Winner on a Tic Tac Toe Game

    地址 https://www.acwing.com/solution/LeetCode/content/6670/ 题目描述A 和 B 在一个 3 x 3 的网格上玩井字棋. 井字棋游戏的规则如下: ...

  6. [CareerCup] 17.2 Tic Tac Toe 井字棋游戏

    17.2 Design an algorithm to figure out if someone has won a game oftic-tac-toe. 这道题让我们判断玩家是否能赢井字棋游戏, ...

  7. Epic - Tic Tac Toe

    N*N matrix is given with input red or black.You can move horizontally, vertically or diagonally. If ...

  8. python 井字棋(Tic Tac Toe)

    说明 用python实现了井字棋,整个框架是本人自己构思的,自认为比较满意.另外,90%+的代码也是本人逐字逐句敲的. minimax算法还没完全理解,所以参考了这里的代码,并作了修改. 特点 可以选 ...

  9. ACM-Team Tic Tac Toe

    我的代码: #include <bits/stdc++.h> using namespace std; int main() { char a[3][3]; int i,j=0; for( ...

  10. [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 ...

随机推荐

  1. Sql Server 删除所有表

    如果由于外键约束删除table失败,则先删除所有约束: --/第1步**********删除所有表的外键约束*************************/ DECLARE c1 cursor f ...

  2. HR函数学习03——维护信息类型1008

    REPORT ZLYHR01. DATA:TP1008 TYPE TABLE OF P1008, SP1008 TYPE P1008. SP1008-PLVAR = '. SP1008-OTYPE = ...

  3. win7任务栏只显示日期不显示年月日

    某一天突然发现笔记本任务栏上的时间显示只剩下了时间,没有了年月日 于是百度 搜到的结果大多是如何设置显示的格式  yyyy-MM-dd 继续搜 终于搜到了正确答案 结果令我瞠目结舌  着实无奈 是因为 ...

  4. JAVA 十六进制与字符串的转换

    public static String toHexString(int i)以十六进制的无符号整数形式返回一个整数参数的字符串表示形式.如果参数为负,那么无符号整数值为参数加上 232:否则等于该参 ...

  5. WCF初探-6:WCF服务配置

    WCF服务配置是WCF服务编程的主要部分.WCF作为分布式开发的基础框架,在定义服务以及定义消费服务的客户端时,都使用了配置文件的方法.虽然WCF也提供硬编程的方式,通过在代码中直接设置相关对象的属性 ...

  6. apache下自定义404错误页面

    404页面的目的是:告诉浏览者其所请求的页面不存在或链接错误,同时引导用户使用网站其他页面而不是关闭窗口离开. 很多开源系统包括CMS系统.Blog系统等不提供404页面或提供的404页面并未达到SE ...

  7. Ubuntu 中文输入法安装包

    1. 打开 Dashboard http://www.2cto.com/os/201207/144189.html

  8. terminator终端工具

    terminator是个很好的终端程序,在Ubuntu Linux下安装如下: sudo apt-get install terminator 可在同一屏打开多个窗口:

  9. 简单使用SQLite 的增删改查

    1.插入 第一种方式 INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) VALUES (1, 'Paul', 32, 'California', 200 ...

  10. WCF 断点不会命中

    VS的调试模式改为Debug 工具—选项—调试—常规中的‘要求源文件和原始版本完全匹配’的勾去掉