add: question description
This commit is contained in:
parent
a3ac26c627
commit
923514a3c6
|
|
@ -4,6 +4,30 @@
|
||||||
|
|
||||||
#define LOCAL
|
#define LOCAL
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* The mouse starts at node 1 and goes first, the 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 three 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 (i.e., 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 mouse wins the game,
|
||||||
|
* 2 if the cat wins the game, or
|
||||||
|
* 0 if the game is a draw.
|
||||||
|
*/
|
||||||
|
|
||||||
class Solution {
|
class Solution {
|
||||||
private:
|
private:
|
||||||
// dp[][][0]: previous moved is mouse, [1] cat.
|
// dp[][][0]: previous moved is mouse, [1] cat.
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,13 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 1009. Complement of Base 10 Integer
|
||||||
|
* The complement of an integer is the integer you get when you flip all the 0's to 1's and all the 1's to 0's in its binary representation.
|
||||||
|
*
|
||||||
|
* For example, The integer 5 is "101" in binary and its complement is "010" which is the integer 2.
|
||||||
|
* Given an integer n, return its complement.
|
||||||
|
*/
|
||||||
|
|
||||||
class Solution {
|
class Solution {
|
||||||
public:
|
public:
|
||||||
static int bitwiseComplement(int n) {
|
static int bitwiseComplement(int n) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue