首页 > 数据库 >[Oracle] LeetCode 348 Design Tic-Tac-Toe

[Oracle] LeetCode 348 Design Tic-Tac-Toe

时间:2022-08-27 16:00:07浏览次数:56  
标签:int diag player vector Design Tac Oracle col row

Assume the following rules are for the tic-tac-toe game on an n x n board between two players:

  • A move is guaranteed to be valid and is placed on an empty block.
  • Once a winning condition is reached, no more moves are allowed.
  • A player who succeeds in placing n of their marks in a horizontal, vertical, or diagonal row wins the game.

Implement the TicTacToe class:

  • TicTacToe(int n) Initializes the object the size of the board n.
  • int move(int row, int col, int player) Indicates that the player with id player plays at the cell (row, col) of the board. The move is guaranteed to be a valid move.

Solution

按照正常思路,对每行,每列,对角线都 \(check\) 的话,每次都得 \(O(N)\). 但实际上我们只关心出现的次数是否为 \(n\) 即可,所以为每个 \(player\) 分别开个 \(vector\) 记录即可

点击查看代码
class TicTacToe {
private:
    vector<vector<int>> R, C;
    vector<int> diag, r_diag;
    
public:
    TicTacToe(int n) {
        R = vector<vector<int>> (n, vector<int>(3));
        C = vector<vector<int>> (n, vector<int>(3));
        diag = vector<int> (3);
        r_diag = vector<int> (3);
    }
    
    int move(int row, int col, int player) {
        int cnt;
        R[row][player]++; C[col][player]++;
        cnt = max(R[row][player], C[col][player]);
        if(row==col)diag[player]++;
        if(row+col==R.size()-1)r_diag[player]++;
        cnt=max(cnt, max(diag[player], r_diag[player]));
        if(cnt==R.size())return player;
        else return 0;
    }
};

/**
 * Your TicTacToe object will be instantiated and called as such:
 * TicTacToe* obj = new TicTacToe(n);
 * int param_1 = obj->move(row,col,player);
 */

标签:int,diag,player,vector,Design,Tac,Oracle,col,row
From: https://www.cnblogs.com/xinyu04/p/16630755.html

相关文章

  • DataContext使用事务
    1//必须打开连接,用于事务的创建2if(db.Connection.State==ConnectionState.Closed)db.Connection.Open();3using(DbTrans......
  • .htaccess的两种写法和.user.ini
    一、.htaccess文件上传方法一:FileMatch参数即为文件名的正则匹配<FilesMatch"1.jpg"> SetHandlerapplication/x-httpd-php</FilesMatch>//1.jpg<?phpeval($_GET['a......
  • Oracle查看表结构的几种方法
    1,DESCRIBE命令使用方法如下:SQL>describenchar_tst(nchar_tst为表名)显示的结果如下:名称是否为空?类型-----------------------......
  • OpenStack命令行操作
    环境变量OpenStack的九个组件必须熟记,命令不需要死记硬背,我们可以通过help来查询相关的命令和参数。如果你直接使用命令来查询或者做其他操作,那么会涉及到环境变量,操作起......
  • Visual studio 2017 + EF6 + Oracle 更新模型向导闪退解决办法
    问题:从数据库更新模型,点下一步闪退,如图。问题原因:ODACforVisualStudio2017与Oracle.ManagedDataAccess、Oracle.ManagedDataAccess.EntityFramework版本不一致。......
  • Oracle多租户容器数据库的安装和使用
    oracle多租户容器数据库:OracleMultitenantContainerDatabase(CDB)一、多租户架构有oracle体系结构链接:https://www.cnblogs.com/muhai/p/16333182.html二、多租户容......
  • PowerDesigner添加索引(转载)
     原文链接:https://blog.csdn.net/a1720119024/article/details/90732860/生成的sql举例:createuniquenonclusteredindexIX_ZybwhysClass_NameonT_ZybwhysClass(N......
  • HCIA-datacom 8.1 网络编程与自动化基础
    前言:把今天的python讲完,我们的所有HCIA-datacom的实验就做完了,但是这就够了吗?不够的,我们还需要做一个综合实验。但是综合实验,我就不会像前面讲解的这么细致了,因为如果你不......
  • oracle数据库备份一个表数据并恢复
    使用场景:当我们平时想要大批量替换数据的时候,在生产上往往会先备份,然后如果遇到问题再回退,那么可能涉及下面两个语句:1.创建一个备份表并存储原始数据CREATETABLE备份......
  • ant-design上传组件方法beforeUpload返回false或promise.reject仍然失效
    问题描述:在使用antdesign框架的Upload上传组件时,相信很多人做过上传文件的格式、大小、数量、或其他依赖条件等的限制,这些限制一般都是需要在beforeUpload方法中进行处理......