Leetcode-cn.com 2022-05-10
🔴 1728.cat-and-mouse-ii
🏷️ Tags
#breadth_first_search #graph #memoization #math #dynamic_programming #game_theory
Description
一只猫和一只老鼠在玩一个叫做猫和老鼠的游戏。
它们所处的环境设定是一个
玩家由字符
地板由字符
墙用字符
食物用字符
字符
猫和老鼠按照如下规则移动:
老鼠 先移动 ,然后两名玩家轮流移动。
每一次操作时,猫和老鼠可以跳到上下左右四个方向之一的格子,他们不能跳过墙也不能跳出
它们可以停留在原地。
老鼠可以跳跃过猫的位置。
游戏有 4 种方式会结束:
如果猫跟老鼠处在相同的位置,那么猫获胜。
如果猫先到达食物,那么猫获胜。
如果老鼠先到达食物,那么老鼠获胜。
如果老鼠不能在 1000 次操作以内到达食物,那么猫获胜。
给你
Example
🔴 1728.cat-and-mouse-ii
🏷️ Tags
#breadth_first_search #graph #memoization #math #dynamic_programming #game_theory
Description
一只猫和一只老鼠在玩一个叫做猫和老鼠的游戏。
它们所处的环境设定是一个
rows x cols 的方格 grid ,其中每个格子可能是一堵墙、一块地板、一位玩家(猫或者老鼠)或者食物。玩家由字符
'C' (代表猫)和 'M' (代表老鼠)表示。地板由字符
'.' 表示,玩家可以通过这个格子。墙用字符
'#' 表示,玩家不能通过这个格子。食物用字符
'F' 表示,玩家可以通过这个格子。字符
'C' , 'M' 和 'F' 在 grid 中都只会出现一次。猫和老鼠按照如下规则移动:
老鼠 先移动 ,然后两名玩家轮流移动。
每一次操作时,猫和老鼠可以跳到上下左右四个方向之一的格子,他们不能跳过墙也不能跳出
grid 。catJump 和 mouseJump 是猫和老鼠分别跳一次能到达的最远距离,它们也可以跳小于最大距离的长度。它们可以停留在原地。
老鼠可以跳跃过猫的位置。
游戏有 4 种方式会结束:
如果猫跟老鼠处在相同的位置,那么猫获胜。
如果猫先到达食物,那么猫获胜。
如果老鼠先到达食物,那么老鼠获胜。
如果老鼠不能在 1000 次操作以内到达食物,那么猫获胜。
给你
rows x cols 的矩阵 grid 和两个整数 catJump 和 mouseJump ,双方都采取最优策略,如果老鼠获胜,那么请你返回 true ,否则返回 false 。Example
输入:grid = ["####F","#C...","M...."], catJump = 1, mouseJump = 2
输出:true
解释:猫无法抓到老鼠,也没法比老鼠先到达食物。
Leetcode-cn.com 2022-05-22
🟡 464.can-i-win
🏷️ Tags
#bit_manipulation #memoization #math #dynamic_programming #bitmask #game_theory
Description
在 "100 game" 这个游戏中,两名玩家轮流选择从
如果我们将游戏规则改为 “玩家 不能 重复使用整数” 呢?
例如,两个玩家可以轮流从公共整数池中抽取从 1 到 15 的整数(不放回),直到累计整数和 >= 100。
给定两个整数
Example
🟡 464.can-i-win
🏷️ Tags
#bit_manipulation #memoization #math #dynamic_programming #bitmask #game_theory
Description
在 "100 game" 这个游戏中,两名玩家轮流选择从
1 到 10 的任意整数,累计整数和,先使得累计整数和 达到或超过 100 的玩家,即为胜者。如果我们将游戏规则改为 “玩家 不能 重复使用整数” 呢?
例如,两个玩家可以轮流从公共整数池中抽取从 1 到 15 的整数(不放回),直到累计整数和 >= 100。
给定两个整数
maxChoosableInteger (整数池中可选择的最大数)和 desiredTotal(累计和),若先出手的玩家是否能稳赢则返回 true ,否则返回 false 。假设两位玩家游戏时都表现 最佳 。Example
输入:maxChoosableInteger = 10, desiredTotal = 11
输出:false
解释:
无论第一个玩家选择哪个整数,他都会失败。
第一个玩家可以选择从 1 到 10 的整数。
如果第一个玩家选择 1,那么第二个玩家只能选择从 2 到 10 的整数。
第二个玩家可以通过选择整数 10(那么累积和为 11 >= desiredTotal),从而取得胜利.
同样地,第一个玩家选择任意其他整数,第二个玩家都会赢。
leetcode.com 2023-07-28
🟡486.predict-the-winner
🏷️ Tags
#recursion #array #math #dynamic_programming #game_theory
🟡486.predict-the-winner
🏷️ Tags
#recursion #array #math #dynamic_programming #game_theory
Telegraph
predict-the-winner
You are given an integer array nums. Two players are playing a game with this array: player 1 and player 2. Player 1 and player 2 take turns, with player 1 starting first. Both players start the game with a score of 0. At each turn, the player takes one of…
leetcode.com 2023-10-02
🟡2038.remove-colored-pieces-if-both-neighbors-are-the-same-color
🏷️ Tags
#greedy #math #string #game_theory
🟡2038.remove-colored-pieces-if-both-neighbors-are-the-same-color
🏷️ Tags
#greedy #math #string #game_theory
Telegraph
remove-colored-pieces-if-both-neighbors-are-the-same-color
There are n pieces arranged in a line, and each piece is colored either by 'A' or by 'B'. You are given a string colors of length n where colors[i] is the color of the ith piece. Alice and Bob are playing a game where they take alternating turns removing…
leetcode.com 2023-11-24
🟡1561.maximum-number-of-coins-you-can-get
🏷️ Tags
#greedy #array #math #game_theory #sorting
🟡1561.maximum-number-of-coins-you-can-get
🏷️ Tags
#greedy #array #math #game_theory #sorting
Telegraph
maximum-number-of-coins-you-can-get
There are 3n piles of coins of varying size, you and your friends will take piles of coins as follows:
leetcode.cn 2024-02-02
🟡1686.stone-game-vi
🏷️ Tags
#greedy #array #math #game_theory #sorting #heap_priority_queue
🟡1686.stone-game-vi
🏷️ Tags
#greedy #array #math #game_theory #sorting #heap_priority_queue
Telegraph
stone-game-vi
Alice 和 Bob 轮流玩一个游戏,Alice 先手。 一堆石子里总共有 n 个石子,轮到某个玩家时,他可以 移出 一个石子并得到这个石子的价值。Alice 和 Bob 对石子价值有 不一样的的评判标准 。双方都知道对方的评判标准。 给你两个长度为 n 的整数数组 aliceValues 和 bobValues 。aliceValues[i] 和 bobValues[i] 分别表示 Alice 和 Bob 认为第 i 个石子的价值。 所有石子都被取完后,得分较高的人为胜者。如果两个玩家得分相同,那么为平局。两位玩家都会采用…