problemscpp
A collection of my answers to algorithm problems in c++.
Public 成员函数 | Public 属性 | 所有成员列表
leetcode::cat_and_mouse::Solution类 参考

#include <leetcode.h>

Public 成员函数

int catMouseGame (vector< vector< int > > &graph)
 
void getNextResult (int mouse, int cat, int turns)
 
int getResult (int mouse, int cat, int turns)
 

Public 属性

int dp [MAXN][MAXN][MAXN *2]
 
vector< vector< int > > graph
 
int n
 

详细描述

在文件 leetcode.h233 行定义.

成员函数说明

◆ catMouseGame()

int leetcode::cat_and_mouse::Solution::catMouseGame ( vector< vector< int > > &  graph)

在文件 leetcode.cpp494 行定义.

494 {
495 this->n = graph.size();
496 this->graph = graph;
497 memset(dp, -1, sizeof dp);
498 return getResult(1, 2, 0);
499 }
int getResult(int mouse, int cat, int turns)
Definition: leetcode.cpp:501
int dp[MAXN][MAXN][MAXN *2]
Definition: leetcode.h:236
vector< vector< int > > graph
Definition: leetcode.h:237

引用了 dp, getResult(), graph , 以及 n.

◆ getNextResult()

void leetcode::cat_and_mouse::Solution::getNextResult ( int  mouse,
int  cat,
int  turns 
)

在文件 leetcode.cpp517 行定义.

517 {
518 const int curMove = turns % 2 == 0 ? mouse : cat;
519 const int defaultResult = curMove == mouse ? CAT_WIN : MOUSE_WIN;
520 int result = defaultResult;
521 for(int next: graph[curMove]) {
522 if(curMove == cat && next == 0) {
523 continue;
524 }
525 const int nextMouse = curMove == mouse ? next : mouse;
526 const int nextCat = curMove == cat ? next : cat;
527 const int nextResult = getResult(nextMouse, nextCat, turns + 1);
528 if(nextResult != defaultResult) {
529 result = nextResult;
530 if(result != DRAW) {
531 break;
532 }
533 }
534 }
535 dp[mouse][cat][turns] = result;
536 }

引用了 leetcode::cat_and_mouse::CAT_WIN, dp, leetcode::cat_and_mouse::DRAW, getResult(), graph , 以及 leetcode::cat_and_mouse::MOUSE_WIN.

被这些函数引用 getResult().

◆ getResult()

int leetcode::cat_and_mouse::Solution::getResult ( int  mouse,
int  cat,
int  turns 
)

在文件 leetcode.cpp501 行定义.

501 {
502 if(turns == n * 2) {
503 return DRAW;
504 }
505 if(dp[mouse][cat][turns] < 0) {
506 if(mouse == 0) {
507 dp[mouse][cat][turns] = MOUSE_WIN;
508 } else if(cat == mouse) {
509 dp[mouse][cat][turns] = CAT_WIN;
510 } else {
511 getNextResult(mouse, cat, turns);
512 }
513 }
514 return dp[mouse][cat][turns];
515 }
void getNextResult(int mouse, int cat, int turns)
Definition: leetcode.cpp:517

引用了 leetcode::cat_and_mouse::CAT_WIN, dp, leetcode::cat_and_mouse::DRAW, getNextResult(), leetcode::cat_and_mouse::MOUSE_WIN , 以及 n.

被这些函数引用 catMouseGame() , 以及 getNextResult().

类成员变量说明

◆ dp

int leetcode::cat_and_mouse::Solution::dp[MAXN][MAXN][MAXN *2]

在文件 leetcode.h236 行定义.

被这些函数引用 catMouseGame(), getNextResult() , 以及 getResult().

◆ graph

vector<vector<int> > leetcode::cat_and_mouse::Solution::graph

在文件 leetcode.h237 行定义.

被这些函数引用 catMouseGame() , 以及 getNextResult().

◆ n

int leetcode::cat_and_mouse::Solution::n

在文件 leetcode.h235 行定义.

被这些函数引用 catMouseGame() , 以及 getResult().


该类的文档由以下文件生成: