[LeetCode] 913. Cat and Mouse 猫和老鼠
A game on an undirected graph is played by two players, Mouse and Cat, who alternate turns.
The graph is given as follows: graph[a]
is a list of all nodes b
such that ab
is an edge of the graph.
Mouse starts at node 1 and goes first, Cat starts at node 2 and goes second, and there is a Hole at node 0.
During each player's turn, they must travel along one edge of the graph that meets where they are. For example, if the Mouse is at node 1
, it must travel to any node in graph[1]
.
Additionally, it is not allowed for the Cat to travel to the Hole (node 0.)
Then, the game can end in 3 ways:
- If ever the Cat occupies the same node as the Mouse, the Cat wins.
- If ever the Mouse reaches the Hole, the Mouse wins.
- If ever a position is repeated (ie. the players are in the same position as a previous turn, and it is the same player's turn to move), the game is a draw.
Given a graph
, and assuming both players play optimally, return 1
if the game is won by Mouse, 2
if the game is won by Cat, and 0
if the game is a draw.
Example 1:
Input: [[2,5],[3],[0,4,5],[1,4,5],[2,3],[0,2,3]]
Output: 0
Explanation: 4---3---1
| |
2---5
\ /
0
Note:
3 <= graph.length <= 50
- It is guaranteed that
graph[1]
is non-empty. - It is guaranteed that
graph[2]
contains a non-zero element.
Github 同步地址:
https://github.com/grandyang/leetcode/issues/913
参考资料:
https://leetcode.com/problems/cat-and-mouse/
LeetCode All in One 题目讲解汇总(持续更新中...)
原文地址:https://www.cnblogs.com/grandyang/p/11515655.html
- 如何搭建你自己的“深度学习”机器?
- MySQL INSERT INTO...ON DUPLICATE KEY UPDATE的使用
- 通过Java代码来模拟乘法器
- INET_ATON()函数在MySQL5.6版本和5.7版本的差异
- Linux主机之间ssh免密登录配置
- 远控木马Posion Ivy开始肆虐缅甸和其它亚洲国家
- Slf4j+Logback配置文件变量使用小记
- Storm消息处理可靠性保证
- git+github创建分支&提交并贡献代码(linux环境)
- 使用Nginx代理restful实现SSL链路加密
- 使用Nginx代理thrift NIO实现SSL链路加密
- TThreadedSelectorServer介绍及Direct Memory OOM分析
- 通过Java程序提交通用Mapreduce任务并获取Job信息
- Mapreduce 任务提交源码分析1
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- 我常用的一些linux命令小结
- linux下安装mongodb教程
- Android中使用TagFlowLayout制作动态添加删除标签
- Android时间对话框使用方法详解
- Ubuntu基础设定:openssh-server的安装和使用介绍
- Android ProgressDialog的实例详解
- linux下获取文件的创建时间与实战教程
- Android 判断网络状态及开启网路
- Android判断后台服务是否开启的两种方法实例详解
- 在CentOS7上搭建Jenkins+Maven+Git持续集成环境的方法
- Linux 实现定时文件占用磁盘空间大小操作方法
- Android开发之文件操作详解
- Linux查看服务器硬件信息的方法步骤
- Android实现EditText的富文本编辑
- Android仿搜狐视频、微视等列表播放视频功能