小白书上经典DFS题目。

1. 递归实现

  1. // from: https://www.cnblogs.com/huaszjh/p/4686092.html
  2. #include <stdio.h>
  3. #include <string.h>
  4. #define maxn 105
  5. unsigned char data[maxn][maxn];
  6. int m, n, vis[maxn][maxn];
  7. void dfs(int x, int y, int ans) {
  8. if (x < 0 || x >= m || y < 0 || y >= n) return; //出界
  9. if (vis[x][y] > 0 || data[x][y] == '*') return; //非'@'或已经访问
  10. vis[x][y] = ans; //连通分量编号
  11. for (int k = -1; k <= 1; k++) {
  12. for (int t = -1; t <= 1; t++) {
  13. if (k != 0 || t != 0) { //自身格子不需要重复判断
  14. dfs(x + k, y + t, ans);
  15. }
  16. }
  17. }
  18. }
  19. #define DEBUG
  20. int main() {
  21. #ifdef DEBUG
  22. const char* input_txt_pth = "F:/zhangzhuo/debug/OJ/UVA-572.txt";
  23. freopen(input_txt_pth, "r", stdin);
  24. #endif
  25. int i, j;
  26. while (scanf("%d %d", &m, &n) && m &&n) {
  27. int count = 0; //连通块
  28. memset(vis, 0, sizeof(vis));
  29. for (i = 0; i < m; i++) {
  30. scanf("%s", data[i]);
  31. }
  32. for (i = 0; i < m; i++) {
  33. for (j = 0; j < n; j++) {
  34. //对未访问且为`@`的格子进行访问
  35. if (vis[i][j] == 0 && data[i][j] == '@') {
  36. dfs(i, j, ++count);
  37. }
  38. }
  39. }
  40. printf("%d\n", count);
  41. #ifdef DEBUG
  42. for (i = 0; i < m; i++) {
  43. for (j = 0; j < n; j++) {
  44. printf("%3d", vis[i][j]);
  45. }
  46. printf("\n");
  47. }
  48. printf("\n");
  49. #endif
  50. }
  51. return 0;
  52. }

2. 递归dfs函数用迭代实现

每个节点的dfs递归调用,改成用stack容器就地计算,是个while循环,本质上还是栈,但是避免了递归时嵌套产生的开销造成的潜在风险。

C++的stack、vector容器用起来比较顺手。另外就是把坐标简单封装为一个结构体。

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <iostream>
  4. #include <stack>
  5. #include <vector>
  6. typedef struct Coord {
  7. char x, y;
  8. } Coord;
  9. #define DEBUG
  10. int main() {
  11. #ifdef DEBUG
  12. const char* input_txt_pth = "F:/zhangzhuo/debug/OJ/UVA-572.txt";
  13. freopen(input_txt_pth, "r", stdin);
  14. #endif
  15. int m, n, i, j;
  16. #define maxn 105
  17. unsigned char data[maxn][maxn];
  18. int vis[maxn][maxn];
  19. while (scanf("%d %d", &m, &n) && m &&n) {
  20. int count = 0; //连通块
  21. memset(vis, 0, sizeof(vis));
  22. for (i = 0; i < m; i++) {
  23. scanf("%s", data[i]);
  24. }
  25. std::stack<Coord> stk;
  26. Coord cd;
  27. std::vector<Coord>offset;
  28. cd.x = -1; cd.y = -1; offset.push_back(cd);
  29. cd.x = -1; cd.y = 0; offset.push_back(cd);
  30. cd.x = -1; cd.y = 1; offset.push_back(cd);
  31. cd.x = 0; cd.y = -1; offset.push_back(cd);
  32. cd.x = 0; cd.y = 1; offset.push_back(cd);
  33. cd.x = 1; cd.y = -1; offset.push_back(cd);
  34. cd.x = 1; cd.y = 0; offset.push_back(cd);
  35. cd.x = 1; cd.y = 1; offset.push_back(cd);
  36. for (i = 0; i < m; i++) {
  37. for (j = 0; j < n; j++) {
  38. cd.x = i; cd.y = j;
  39. if (vis[cd.x][cd.y] > 0 || data[cd.x][cd.y] != '@') continue;
  40. count++;
  41. stk.push(cd);
  42. while (!stk.empty()) {
  43. cd = stk.top();
  44. stk.pop();
  45. vis[cd.x][cd.y] = count;
  46. Coord tmp;
  47. for (size_t k = 0; k < offset.size(); k++) {
  48. tmp.x = cd.x + offset[k].x;
  49. tmp.y = cd.y + offset[k].y;
  50. if (tmp.x < 0 || tmp.x >= m || tmp.y < 0 || tmp.y >= n) continue;
  51. if (vis[tmp.x][tmp.y] > 0 || data[tmp.x][tmp.y] != '@') continue;
  52. stk.push(tmp);
  53. }
  54. }
  55. }
  56. }
  57. printf("%d\n", count);
  58. #ifdef DEBUG
  59. for (i = 0; i < m; i++) {
  60. for (j = 0; j < n; j++) {
  61. printf("%3d", vis[i][j]);
  62. }
  63. printf("\n");
  64. }
  65. printf("\n");
  66. #endif
  67. }
  68. return 0;
  69. }

3.纯C,DFS非递归,自定义栈ADT,函数指针

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. typedef struct Coord Coord;
  6. struct Coord {
  7. char x, y;
  8. };
  9. typedef struct CoordOffset CoordOffset;
  10. struct CoordOffset {
  11. size_t num;
  12. int* x;
  13. int* y;
  14. };
  15. typedef struct ListNode ListNode;
  16. struct ListNode
  17. {
  18. ListNode* next;
  19. void* data;
  20. };
  21. typedef struct Stack Stack;
  22. struct Stack {
  23. ListNode* head;
  24. size_t len;
  25. void(*push_coord)(Stack* stk, Coord* coord);
  26. void (*pop_coord)(Stack* stk);
  27. void (*top_coord)(Stack* stk, Coord* coord);
  28. };
  29. void stack_push_coord(Stack* stk, Coord* coord) {
  30. ListNode* new_head = (ListNode*)malloc(sizeof(ListNode));
  31. /* new_head->data = coord; */
  32. new_head->data = (Coord*)malloc(sizeof(ListNode));
  33. memcpy(new_head->data, coord, sizeof(Coord));
  34. new_head->next = stk->head;
  35. stk->head = new_head;
  36. stk->len++;
  37. }
  38. void stack_pop_coord(Stack* stk) {
  39. if (stk->head != NULL) {
  40. ListNode* new_head = stk->head->next;
  41. free(stk->head->data);
  42. free(stk->head);
  43. stk->head = new_head;
  44. stk->len--;
  45. }
  46. }
  47. void stack_top_coord(Stack* stk, Coord* coord) {
  48. if (stk->head != NULL) {
  49. Coord* t_coord = (Coord*)(stk->head->data);
  50. coord->x = t_coord->x;
  51. coord->y = t_coord->y;
  52. }
  53. }
  54. void make_stack(Stack** _stk) {
  55. Stack* stk = (Stack*)malloc(sizeof(Stack));
  56. stk->head = NULL;
  57. stk->len = 0;
  58. stk->push_coord = stack_push_coord;
  59. stk->pop_coord = stack_pop_coord;
  60. stk->top_coord = stack_top_coord;
  61. /* write back */
  62. *_stk = stk;
  63. }
  64. void free_stack(Stack* stk) {
  65. ListNode* cur = stk->head;
  66. ListNode* temp;
  67. size_t i;
  68. for (i = 0; i < stk->len; i++) {
  69. temp = cur->next;
  70. free(cur->data);
  71. free(cur);
  72. cur = temp;
  73. }
  74. free(stk);
  75. stk = NULL;
  76. }
  77. void make_8coord_offset(CoordOffset** _offset) {
  78. CoordOffset* offset = (CoordOffset*)malloc(sizeof(CoordOffset));
  79. offset->num = 8;
  80. offset->x = (int*)malloc(sizeof(int)*offset->num);
  81. offset->y = (int*)malloc(sizeof(int)*offset->num);
  82. offset->x[0] = -1; offset->y[0] = -1;
  83. offset->x[1] = -1; offset->y[1] = 0;
  84. offset->x[2] = -1; offset->y[2] = 1;
  85. offset->x[3] = 0; offset->y[3] = -1;
  86. offset->x[4] = 0; offset->y[4] = 1;
  87. offset->x[5] = 1; offset->y[5] = -1;
  88. offset->x[6] = 1; offset->y[6] = 0;
  89. offset->x[7] = 1; offset->y[7] = 1;
  90. /* write back */
  91. *_offset = offset;
  92. }
  93. void free_coord_offset(CoordOffset* offset) {
  94. if (offset) {
  95. if (offset->x) {
  96. free(offset->x);
  97. offset->x = NULL;
  98. }
  99. if (offset->y) {
  100. free(offset->y);
  101. offset->y = NULL;
  102. }
  103. free(offset);
  104. offset = NULL;
  105. }
  106. }
  107. /* #define DEBUG */
  108. int main() {
  109. #ifdef DEBUG
  110. const char* input_txt_pth = "F:/zhangzhuo/debug/OJ/UVA-572.txt";
  111. freopen(input_txt_pth, "r", stdin);
  112. #endif
  113. int m, n, i, j;
  114. size_t k;
  115. #define maxn 105
  116. unsigned char data[maxn][maxn];
  117. int vis[maxn][maxn];
  118. /* here we use 8 neighbours */
  119. CoordOffset* offset = NULL;
  120. make_8coord_offset(&offset);
  121. while (scanf("%d %d", &m, &n) && m &&n) {
  122. int count = 0; /* 连通块 */
  123. memset(vis, 0, sizeof(vis));
  124. for (i = 0; i < m; i++) {
  125. scanf("%s", data[i]);
  126. }
  127. /* std::stack<Coord> stk; */
  128. Stack* stk;
  129. make_stack(&stk);
  130. Coord cd;
  131. for (i = 0; i < m; i++) {
  132. for (j = 0; j < n; j++) {
  133. cd.x = i; cd.y = j;
  134. if (vis[cd.x][cd.y] > 0 || data[cd.x][cd.y] != '@') continue;
  135. count++;
  136. /* stk.push(cd); */
  137. stack_push_coord(stk, &cd);
  138. /* while (!stk.empty()) { */
  139. while(stk->len!=0) {
  140. /* cd = stk.top(); */
  141. /* stack_top_coord(stk, &cd); */
  142. stk->top_coord(stk, &cd);
  143. /* stk.pop(); */
  144. /* stack_pop_coord(stk); */
  145. stk->pop_coord(stk);
  146. vis[cd.x][cd.y] = count;
  147. Coord tmp;
  148. for (k = 0; k < offset->num; k++) {
  149. tmp.x = cd.x + offset->x[k];
  150. tmp.y = cd.y + offset->y[k];
  151. if (tmp.x < 0 || tmp.x >= m || tmp.y < 0 || tmp.y >= n) continue;
  152. if (vis[tmp.x][tmp.y] > 0 || data[tmp.x][tmp.y] != '@') continue;
  153. /* stk.push(tmp); */
  154. /* stack_push_coord(stk, &tmp); */
  155. stk->push_coord(stk, &tmp);
  156. }
  157. }
  158. }
  159. }
  160. free_stack(stk);
  161. printf("%d\n", count);
  162. #ifdef DEBUG
  163. for (i = 0; i < m; i++) {
  164. for (j = 0; j < n; j++) {
  165. printf("%3d", vis[i][j]);
  166. }
  167. printf("\n");
  168. }
  169. printf("\n");
  170. #endif
  171. }
  172. free_coord_offset(offset);
  173. return 0;
  174. }

4.DFS+并查集实现

  1. #include <stdio.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. int fa[10500];
  6. int m, n, cnt, vis[105][105];
  7. char mp[105][105];
  8. int find(int x) {
  9. if (fa[x] == x) return x;
  10. fa[x] = find(fa[x]);
  11. return fa[x];
  12. }
  13. void merge(int x, int y) {
  14. int fx = find(x);
  15. int fy = find(y);
  16. if (fx == fy) return;
  17. fa[fx] = fy;
  18. }
  19. void dfs(int x, int y, int fx, int fy) {
  20. if (x < 0 || x >= m || y < 0 || y >= n) return;
  21. if (vis[x][y] || mp[x][y] == '*') return;
  22. vis[x][y] = 1;
  23. /* cout<<"x || y || fx || fy : "<<x<<" || "<<y<<" || "<<fx<<" || "<<fy<<endl; */
  24. if (fx != -1) {
  25. merge(x*m + y, fx*m + fy);
  26. }
  27. int i, j;
  28. for (i = -1; i < 2; i++) {
  29. for (j = -1; j < 2; j++) {
  30. if (!i && !j) continue;
  31. dfs(x + i, y + j, x, y);
  32. }
  33. }
  34. }
  35. /* #define LOCAL */
  36. int main() {
  37. #ifdef LOCAL
  38. const char* input_txt = "F:/zhangzhuo/debug/OJ/UVA-572.txt";
  39. freopen(input_txt, "r", stdin);
  40. #endif
  41. int i, j;
  42. while (scanf("%d%d", &m, &n) == 2 && m && n) {
  43. cnt = 0;
  44. memset(vis, 0, sizeof(vis));
  45. for (i = 0; i < m; i++) {
  46. scanf("%s", mp[i]);
  47. }
  48. for (i = 0; i < 10500; i++) {
  49. fa[i] = i;
  50. }
  51. for (i = 0; i < m; i++) {
  52. for (j = 0; j < n; j++) {
  53. if (!vis[i][j] && mp[i][j] == '@') {
  54. dfs(i, j, -1, -1);
  55. cnt++;
  56. }
  57. }
  58. }
  59. printf("%d\n", cnt);
  60. #ifdef LOCAL
  61. for (i = 0; i < m; i++) {
  62. for (j = 0; j < n; j++) {
  63. printf("%3d", vis[i][j]);
  64. }
  65. printf("\n");
  66. }
  67. printf("\n");
  68. #endif
  69. }
  70. return 0;
  71. }

5.DFS+并查集+不使用全局变量+简单封装为结构体

修改自 UVA572 (并查集解法) 。这种写法有点问题:已经用了dfs,dfs里用并查集多此一举,如果用并查集就不应该递归调用dfs。

  1. #include <stdio.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. typedef struct FSU_Node {
  6. int p; /* parent id */
  7. int rank;
  8. int vis; /* group(connected component) id */
  9. } FSU_Node;
  10. /*
  11. get node's root id
  12. @param x: node id
  13. @param nodes: all nodes in map
  14. */
  15. int fus_find(int x, FSU_Node* nodes) {
  16. if (nodes[x].p == x) return x;
  17. nodes[x].p = fus_find(nodes[x].p, nodes);
  18. return nodes[x].p;
  19. }
  20. /*
  21. merge two node groups
  22. @param a: a node from one node group
  23. @param b: a node from another node group
  24. */
  25. void fus_union(int a, int b, FSU_Node* nodes)
  26. {
  27. int ra = fus_find(a, nodes); /* ra: root id of a */
  28. int rb = fus_find(b, nodes); /* rb: root id of b */
  29. if (ra == rb) {
  30. return;
  31. }
  32. if (nodes[ra].rank > nodes[rb].rank)
  33. {
  34. nodes[rb].p = ra;
  35. }
  36. else {
  37. if (nodes[ra].rank == nodes[rb].rank)
  38. {
  39. nodes[rb].rank++;
  40. }
  41. nodes[ra].p = rb;
  42. }
  43. }
  44. typedef struct ImageSize {
  45. int w, h;
  46. } ImageSize;
  47. typedef struct Coord {
  48. int row, col;
  49. } Coord;
  50. void fus_dfs(const Coord* pt, const Coord* f_pt, FSU_Node* nodes, ImageSize* sz, unsigned char* mp) {
  51. int row = pt->row;
  52. int col = pt->col;
  53. int f_row = f_pt->row;
  54. int f_col = f_pt->col;
  55. if (row < 0 || row >= sz->h || col < 0 || col >= sz->w) return;
  56. int id = row * sz->w + col;
  57. int fid = f_row * sz->w + f_col;
  58. /* if (vis[id] || mp[id] == '*') return; */
  59. if (nodes[id].vis || mp[id] == '*') return;
  60. /* vis[id] = 1; */
  61. nodes[id].vis = 1;
  62. if (f_row != -1) {
  63. fus_union(id, fid, nodes);
  64. }
  65. int i, j;
  66. Coord neighbor;
  67. for (i = -1; i < 2; i++) {
  68. for (j = -1; j < 2; j++) {
  69. if (!i && !j) continue;
  70. neighbor.row = row + i;
  71. neighbor.col = col + j;
  72. fus_dfs(&neighbor, pt, nodes, sz, mp);
  73. }
  74. }
  75. }
  76. /*#define LOCAL*/
  77. int main() {
  78. #ifdef LOCAL
  79. const char* input_txt = "F:/zhangzhuo/debug/OJ/UVA-572.txt";
  80. freopen(input_txt, "r", stdin);
  81. #endif
  82. #define MAXN 105
  83. int m, n, cnt, i, j;
  84. /* int vis[MAXN*MAXN]; */
  85. unsigned char mp[MAXN*MAXN];
  86. FSU_Node nodes[MAXN*MAXN];
  87. int idx;
  88. while (scanf("%d%d", &m, &n) == 2 && m && n) {
  89. cnt = 0;
  90. /* memset(vis, 0, sizeof(int)*MAXN*MAXN); */
  91. for (i = 0; i < m; i++) {
  92. for (j = 0; j < n; j++) {
  93. idx = i * n + j;
  94. scanf(" %c", &mp[idx]);
  95. /* printf("! %c !", mp[idx]); */
  96. }
  97. }
  98. for (i = 0; i < m*n; i++) {
  99. nodes[i].p = idx;
  100. nodes[i].rank = 1;
  101. nodes[i].vis = 0;
  102. }
  103. ImageSize im_sz;
  104. im_sz.h = m;
  105. im_sz.w = n;
  106. Coord pt;
  107. Coord f_pt;
  108. f_pt.row = -1;
  109. f_pt.col = -1;
  110. for (i = 0; i < m; i++) {
  111. for (j = 0; j < n; j++) {
  112. idx = i * n + j;
  113. /* if (!vis[idx] && mp[idx] == '@') { */
  114. if (!nodes[idx].vis && mp[idx] == '@') {
  115. /* dfs(i, j, -1, -1); */
  116. pt.row = i;
  117. pt.col = j;
  118. /* fus_dfs(&pt, &f_pt, nodes, &im_sz, vis, mp); */
  119. fus_dfs(&pt, &f_pt, nodes, &im_sz, mp);
  120. cnt++;
  121. }
  122. }
  123. }
  124. printf("%d\n", cnt);
  125. #ifdef LOCAL
  126. for (i = 0; i < m; i++) {
  127. for (j = 0; j < n; j++) {
  128. idx = i * m + j;
  129. /* printf("%3d", vis[idx]); */
  130. printf("%c", mp[idx]);
  131. }
  132. printf("\n");
  133. }
  134. printf("\n");
  135. #endif
  136. }
  137. return 0;
  138. }

这里的教训是,如果在双重for循环中使用变量x、y来表示坐标,容易把2维度坐标->1维坐标的计算算错。使用row,col能减少犯错可能;

另外就是数据读取,这里改成%c,则需要过滤掉换行符\n,方法是scanf时的格式串首部添加空格:scanf(" %c", &xx)

6. 并查集,去掉了DFS

思路:遍历每个像素点,每个像素点用并查集算法合并周边8邻域中为'@'的像素点。再次遍历,统计每个'@'像素对应的等价类(root节点)的值。第三次遍历,把第二次统计的值当中cnt数大于0的累计,就是区域个数。在统计连通域个数的时候顺带把每个连通域id(像素的parent值)修改为从1开始严格单调增的序列,开启LOCALLOCAL_DEBUG宏可以看到。

和通常用的模板写法略有差别,比如返回root的递归终止条件,比如root初值。

不得不说,uDebug是个好东西。

  1. #include <stdio.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. typedef struct FSU_Node {
  6. int p; /* parent id */
  7. int rank;
  8. } FSU_Node;
  9. /*
  10. get node's root id
  11. @param x: node id
  12. @param nodes: all nodes in map
  13. */
  14. int fus_find(int x, FSU_Node* nodes) {
  15. if (nodes[x].p == x) {
  16. return x;
  17. }
  18. nodes[x].p = fus_find(nodes[x].p, nodes);
  19. return nodes[x].p;
  20. }
  21. /*
  22. merge two node groups
  23. @param a: a node from one node group
  24. @param b: a node from another node group
  25. */
  26. void fus_union(int a, int b, FSU_Node* nodes)
  27. {
  28. int ra = fus_find(a, nodes); /* ra: root id of a */
  29. int rb = fus_find(b, nodes); /* rb: root id of b */
  30. if (ra == rb) {
  31. return;
  32. }
  33. if (nodes[ra].rank > nodes[rb].rank) {
  34. nodes[rb].p = ra;
  35. }
  36. else {
  37. if (nodes[ra].rank == nodes[rb].rank) {
  38. nodes[rb].rank++;
  39. }
  40. nodes[ra].p = rb;
  41. }
  42. }
  43. /* #define LOCAL */
  44. /* #define LOCAL_DEBUG */
  45. int main() {
  46. #ifdef LOCAL
  47. const char* input_txt = "F:/zhangzhuo/debug/OJ/UVA-572.txt";
  48. freopen(input_txt, "r", stdin);
  49. #endif
  50. #define MAXN 105
  51. int m, n, cnt, i, j, k;
  52. int shift_x[8] = { -1, -1, -1, 0, 0, 1, 1, 1 };
  53. int shift_y[8] = { -1, 0, 1, -1, 1, -1, 0, 1 };
  54. unsigned char mp[MAXN*MAXN];
  55. FSU_Node nodes[MAXN*MAXN];
  56. int idx;
  57. while (scanf("%d%d", &m, &n) == 2 && m && n) {
  58. cnt = 0;
  59. for (i = 0; i < m; i++) {
  60. for (j = 0; j < n; j++) {
  61. idx = i * n + j;
  62. scanf(" %c", &mp[idx]);
  63. }
  64. }
  65. for (i = 0; i < m; i++) {
  66. for (j = 0; j < n; j++) {
  67. idx = i * n + j;
  68. nodes[idx].p = idx;
  69. nodes[idx].rank = 1;
  70. }
  71. }
  72. for (i = 0; i < m; i++) {
  73. for (j = 0; j < n; j++) {
  74. idx = i * n + j;
  75. if (mp[idx] != '@') continue;
  76. for (k = 0; k < 8; k++) {
  77. int row = i + shift_x[k];
  78. int col = j + shift_y[k];
  79. int neighbor_idx = row * n + col;
  80. if (row < 0 || row >= m || col < 0 || col >= n || mp[neighbor_idx] != '@') continue;
  81. fus_union(idx, neighbor_idx, nodes);
  82. }
  83. }
  84. }
  85. int bowl[MAXN*MAXN] = { 0 };
  86. int label_cnt = 0;
  87. for (i = 0; i < m*n; i++) {
  88. if (mp[i] != '@') continue;
  89. int t = fus_find(i, nodes);
  90. nodes[i].p = t;
  91. if (bowl[t] == 0) {
  92. label_cnt++;
  93. bowl[t] = label_cnt;
  94. }
  95. }
  96. printf("%d\n", label_cnt);
  97. #ifdef LOCAL_DEBUG
  98. /* print out debug info */
  99. for (i = 0; i < m; i++) {
  100. for (j = 0; j < n; j++) {
  101. idx = i * n + j ;
  102. if (mp[idx] == '@') {
  103. /* printf("%3d", fus_find(idx, nodes)); */
  104. /* printf("%3d", nodes[idx].p); */
  105. printf("%3d", bowl[nodes[idx].p]);
  106. }
  107. else {
  108. printf("%3c", '*');
  109. }
  110. }
  111. printf("\n");
  112. }
  113. printf("\n");
  114. #endif
  115. }
  116. return 0;
  117. }

UVA572 Oil Deposits DFS求解的更多相关文章

  1. UVa572 Oil Deposits DFS求连通块

      技巧:遍历8个方向 ; dr <= ; dr++) ; dc <= ; dc++) || dc != ) dfs(r+dr, c+dc, id); 我的解法: #include< ...

  2. HDOJ(HDU).1241 Oil Deposits(DFS)

    HDOJ(HDU).1241 Oil Deposits(DFS) [从零开始DFS(5)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架 ...

  3. Oil Deposits(dfs)

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...

  4. HDU 1241 Oil Deposits DFS(深度优先搜索) 和 BFS(广度优先搜索)

    Oil Deposits Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...

  5. HDU 1241 Oil Deposits (DFS/BFS)

    Oil Deposits Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tota ...

  6. HDU-1241 Oil Deposits (DFS)

    Oil Deposits Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total ...

  7. HDU_1241 Oil Deposits(DFS深搜)

    Problem Description The GeoSurvComp geologic survey company is responsible for detecting underground ...

  8. UVa 572 Oil Deposits(DFS)

     Oil Deposits  The GeoSurvComp geologic survey company is responsible for detecting underground oil ...

  9. [POJ] 1562 Oil Deposits (DFS)

    Oil Deposits Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 16655   Accepted: 8917 Des ...

随机推荐

  1. C++内存管理2-内存泄漏

    1 C++中动态内存分配引发问题的解决方案 假设我们要开发一个String类,它可以方便地处理字符串数据.我们可以在类中声明一个数组,考虑到有时候字符串极长,我们可以把数组大小设为200,但一般的情况 ...

  2. 安装centos docker ce

    安装centos docker ce 移除旧的版本: $ sudo yum remove docker \ docker-client \ docker-client-latest \ docker- ...

  3. C++11 并发编程库

    C++11 并发编程 C++11 新标准中引入了几个头文件来支持多线程编程,他们分别是: <atomic>:该头文主要声明了两个类, std::atomic 和 std::atomic_f ...

  4. maven更改本地的maven私服

    1.今天想升级一个服务的jar包,更改后 使用命令 mvn deploy -e 一直报错, 看错误信息是  私服地址不是公司现在的地址. 想了半天,原来是电脑一直配置的上家公司的私服地址.. 但是在哪 ...

  5. hbase 操作

    视频随笔视频地址:hbase教程 1.与传统关系型数据库的区别 hbase 传统分布式   单机列动态增减   建表时候指定只有字符串一种数据类型   数值,字符空值不被存储   存储不支持SQL 查 ...

  6. sed取某域名对应的IP

  7. [转帖]Zookeeper

    Zookeeper https://www.cnblogs.com/zhang-qc/p/8877082.html   Zookeeper其实是一种为分布式应用所设计的高可用.高性能且一致的开源协调服 ...

  8. [Linux] 在 Ubuntu 19.10 上开启 SSH 服务并允许远程登录

    在 Ubuntu 19.10 上安装 SSH,并开启服务 0.检查并确认系统当前是否已安装SSH: sudo ps -e | grep ssh 如果只有 ssh-agent 说明 ssh-server ...

  9. CORS解决跨域问题(403问题)

    1.什么是跨域问题? 跨域问题是浏览器对于ajax请求的一种安全限制:一个页面发起的ajax请求,只能是用当前页同域名同端口的路径,这能有效的阻止跨站攻击. 2.跨域问题出现的条件: 1.跨域问题是a ...

  10. Keyboarding

    题目描述 思路 一开始想先写一个bfs,目标字符串要加上一个'*',表示这是一个换行符,然后一个字母一个字母的找,每次重置一下vis数组,bfs返回的结果再加上1,表示要打印这个字母,结果第一个样例没 ...