鱼C论坛

 找回密码
 立即注册
查看: 2140|回复: 13

[已解决]小岛面积

[复制链接]
发表于 2020-8-21 21:35:34 | 显示全部楼层 |阅读模式
20鱼币
本帖最后由 巴巴鲁 于 2020-8-21 21:38 编辑
  1. /*
  2. 1 代表海岸线,0 代表小岛。求小岛面积(即被 1 中包围的 0 的个数)。
  3. 注意:仅求这样的 0,该 0 所在行中被两个 1 包围,该 0 所在列中被两个
  4. */

  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #define N 6 // 假设是6维的方阵

  8. void input(int (*arr)[N]);
  9. int check(int (*arr)[N], int row, int col);

  10. int main(void)
  11. {
  12.                 int i, j;
  13.                 int count = 0;
  14.                 int arr[N][N] = {0};
  15.                
  16.                 input(arr);
  17.                
  18.                 // 由题意知,小岛在矩阵边缘不属于小岛面积
  19.                 for(i = 1; i < N-1; i++)
  20.                 {
  21.                         for(j = 1; j < N-1; j++)
  22.                         {
  23.                                 // 只判断是小岛周围
  24.                                 if(arr[i][j] == 0)
  25.                                 {
  26.                                         if(check(arr, i, j)) // 如果检查后满足条件,小岛面积加1
  27.                                         {
  28.                                                 count++;
  29.                                         }
  30.                                 }
  31.                         }
  32.                 }
  33.                
  34.                 printf("小岛面积为%d\n",count);
  35.                 system("pause");
  36.                 return 0;
  37. }

  38. void input(int (*arr)[N])
  39. {
  40.                 int i, j;
  41.                
  42.                 for(i = 0; i < N; i++)
  43.                 {
  44.                         for(j = 0; j < N; j++)
  45.                         {
  46.                                 scanf("%d",&arr[i][j]); // 只能输入0或1
  47.                                 if(arr[i][j] != 0 && arr[i][j] != 1)
  48.                                 {
  49.                                         printf("输入错误,退出程序");
  50.                                         exit(1);
  51.                                 }
  52.                         }
  53.                 }
  54. }

  55. // 判断是否符合题目要求
  56. int check(int (*arr)[N], int row, int col)
  57. {
  58.                 int h, l, m, n;
  59.                 m = n = 0;
  60.                
  61.                 // 检查行
  62.                 for(h = row, l = col; l >= 0; l--)
  63.                 {
  64.                         if(arr[h][l] == 1)
  65.                         {
  66.                                 for(h = row, l = col; l < N; l++)
  67.                                 {
  68.                                         if(arr[h][l] == 1)
  69.                                         {
  70.                                                 n++; // 都满足,n+1
  71.                                                 break;
  72.                                         }
  73.                                 }
  74.                                 if(n == 1)
  75.                                 {
  76.                                         break;
  77.                                 }
  78.                         }
  79.                 }
  80.                
  81.                 // 检查列
  82.                 for(h = row, l = col; h >= 0; h--)
  83.                 {
  84.                         if(arr[h][l] == 1)
  85.                        
  86.                                 for(h = row, l = col; h < N; h++)
  87.                                 {
  88.                                         if(arr[h][l] == 1)
  89.                                         {
  90.                                                 m++; // 都满足,m+1
  91.                                                 break;
  92.                                         }
  93.                                 }
  94.                                 if(m == 1)
  95.                                 {
  96.                                         break;
  97.                                 }
  98.                 }
  99.                
  100.                 if(m + n == 2) // 两个条件都成立
  101.                 {
  102.                         return 1;
  103.                 }
  104.                 return 0;
  105. }
复制代码

样例输入:
1 1 1 1 1 1
1 1 0 0 0 1
1 0 0 0 1 0
1 1 0 1 1 1
0 1 0 1 0 0
1 1 1 1 1 1
样例输出:
8

我输出之后就这样没反应,是我代码的问题吗?哪个大佬们看一下
最佳答案
2020-8-21 21:35:35
# 太难了
# 链表忘了,又回去复习了一下
# 代码很糟糕
  1. #include<stdio.h>
  2. #include<malloc.h>

  3. #define N 6

  4. typedef struct ZERO //标记不被包围 0 的位置
  5. {
  6.         int count;
  7.         int x;
  8.         int y;
  9.         struct ZERO *next;
  10. } *ZEROP;

  11. int adjacent_to_zero(ZEROP head, ZEROP point); //检查是否与不被包围 0 相邻
  12. void print_struct(ZEROP, char*);
  13. ZEROP pop(ZEROP*, int n, int*);
  14. int main(void)
  15. {
  16.         int arr[N][N] = { 1, 1, 1, 1, 1, 1,
  17.                                           1, 1, 0, 0, 0, 1,
  18.                                           1, 0, 0, 0, 1, 0,
  19.                                           1, 1, 0, 1, 1, 1,
  20.                                           0, 1, 0, 1, 0, 0,
  21.                                           1, 1, 1, 1, 1, 1};
  22.        
  23.         int i = 0;
  24.         int j = 0;
  25.         int count = 0;
  26.         char un_zero_str[20] = "被包围 0";
  27.         char zero_str[20] = "不被包围 0";
  28.         ZEROP head, pn, pend; // head 不被包围 0 的位置头指针
  29.         ZEROP un_head, un_pn, un_pend; // un_head 未知不被包围 0 的位置头指针
  30.         ZEROP temp = NULL;
  31.         for (i=0; i<N; i++) // 查找最外层有没有 0
  32.         {
  33.                 for (j=0; j<N; j++)
  34.                 {
  35.                         if (i == 0 || i == N-1 || j == 0 || j == N-1)
  36.                                 {
  37.                                         if (!arr[i][j])
  38.                                         {
  39.                                                 if (count == 0)
  40.                                                 {
  41.                                                         head = malloc(sizeof(struct ZERO));
  42.                                                         head->x = i;
  43.                                                         head->y = j;       
  44.                                                         head->next = NULL;
  45.                                                         pn = pend = head;
  46.                                                         count++;
  47.                                                         head->count = count;
  48.                                                 }
  49.                                                 else
  50.                                                 {
  51.                                                         count++;
  52.                                                         pend = malloc(sizeof(struct ZERO));
  53.                                                         pn->next = pend;
  54.                                                         pend->count = count;
  55.                                                         pend->x = i;
  56.                                                         pend->y = j;
  57.                                                         pend->next = NULL;
  58.                                                         pn = pend; //标记 1
  59.                                                        
  60.                                                 }
  61.                                                
  62.                                         }
  63.                                         continue;
  64.                                 }
  65.                 }
  66.         }
  67.         int find = 2;
  68.         if (!count) // 最外层没有 0 里面所有0都是被包围的0
  69.         {
  70.                 find = 0;
  71.         }
  72.         int mark = 0;
  73.         int un_count = 0;
  74.         for (i=1; i<N-1; i++)
  75.         {
  76.                 for (j=1; j<N-1; j++)
  77.                 {
  78.                         if (arr[i][j]) continue;
  79.                         temp = malloc(sizeof(struct ZERO));
  80.                         temp->x = i;
  81.                         temp->y = j;
  82.                         temp->next = NULL;
  83.                         if (!find) // 最外层没有 0
  84.                         {
  85.                                 if (count == 0)
  86.                                 {
  87.                                         head = temp;
  88.                                         head->next = NULL;
  89.                                         pn = pend = head;
  90.                                         count++;
  91.                                         head->count = count;
  92.                                         continue;
  93.                                 }
  94.                                 else
  95.                                 {
  96.                                         count++;
  97.                                         pn->next = temp;
  98.                                         temp->count = count;
  99.                                         pn = temp; //标记 1
  100.                                          
  101.                                 }
  102.                         }
  103.                         else if (adjacent_to_zero(head, temp)) // 最外层有 0
  104.                         {
  105.                                 un_count++;
  106.                                 if (!mark)
  107.                                 {
  108.                                         un_head = temp;
  109.                                         un_head->count = un_count;
  110.                                         un_pn = un_head;
  111.                                         mark = 1;
  112.                                         continue;
  113.                                        
  114.                                 }
  115.                                 un_pn->next = temp;
  116.                                 temp->count = un_count;
  117.                                 un_pn = temp;
  118.                         }
  119.                         else
  120.                         {
  121.                                 count ++;
  122.                                 pn->next = temp; //接着标记 1
  123.                                 temp->count = count;
  124.                                 pn = temp;
  125.                         }
  126.                 }
  127.         }
  128.         if (!find) // 最外层没有 0 直接打印结果
  129.         {
  130.                 print_struct(head, zero_str);
  131.                 return 0;
  132.         }
  133.         //print_struct(un_head, un_zero_str);
  134.         temp = un_head;
  135.         int one = 0;
  136.         while (1)
  137.         {
  138.                 one ++;
  139.                 if (! adjacent_to_zero(head, temp)) //将未知 0 转入不被包围的 0
  140.                 {
  141.                         count++;
  142.                         //转入后更新链表
  143.                         if (un_head->next)
  144.                                 temp = pop(&un_head, temp->count, &find);
  145.                         else find = 0;
  146.                         //print_struct(head, zero_str);
  147.                         //printf("count = %d\n", count);
  148.                         temp->count = count;
  149.                         pn->next = temp; //接着标记 1
  150.                         pn = temp;
  151.                         if (!find) break;
  152.                         if (find == 1)
  153.                         {
  154.                                 temp = un_head;
  155.                                 continue;
  156.                         }
  157.                 }
  158.                 //printf("one = %d\n", one);
  159.                 if (!temp->next) break;
  160.                 temp = temp->next;
  161.         }
  162.         //free(p);
  163.         print_struct(head, zero_str);
  164.         if (find)
  165.                 print_struct(un_head, un_zero_str);
  166.         return 0;
  167. }

  168. int adjacent_to_zero(ZEROP head, ZEROP point)
  169. {
  170.         while(1)
  171.         {
  172.                 if (head->x == point->x) //同一行
  173.                 {
  174.                         if (head->y == point->y-1 || head->y == point->y+1)
  175.                                 return 0;
  176.                 }
  177.                 if (head->y == point->y)
  178.                 {
  179.                         if (head->x == point->x+1 || head->x == point->x-1) //同一列
  180.                                 return 0;
  181.                 }
  182.                 if (head->next == NULL) break;
  183.                 head = head->next;
  184.         }
  185.         return 1;
  186. }

  187. void print_struct(ZEROP head, char* title)
  188. {
  189.         printf("%s:\n",title);
  190.         while (1)
  191.         {
  192.                 printf("COUNT = %d\tX = %d\tY = %d\n",head->count ,head->x+1 ,head->y+1);
  193.                 if (!head->next) break;
  194.                 head = head->next;
  195.         }
  196. }

  197. ZEROP pop(ZEROP* linked_list, int n, int* find)
  198. {
  199.         int count = 0;
  200.         ZEROP result, previous;
  201.         previous = result = *linked_list;
  202.         while (1)
  203.         {
  204.                 if (previous->count == n && count == 0)
  205.                 {
  206.                         *linked_list = previous->next;
  207.                         *find = 1;
  208.                         return previous;
  209.                 }
  210.                 else if (result->count == n)
  211.                 {
  212.                         previous->next = result->next;
  213.                         *find = 1;
  214.                         return result;
  215.                 }
  216.                 if (!result->next) break;
  217.                 previous = result;
  218.                 result = result->next;
  219.         }
  220.         *find = 2;
  221.         return result;
  222. }
复制代码

result:
  1. 不被包围 0:
  2. COUNT = 1       X = 3   Y = 6
  3. COUNT = 2       X = 5   Y = 1
  4. COUNT = 3       X = 5   Y = 6
  5. COUNT = 4       X = 5   Y = 5
  6. 被包围 0:
  7. COUNT = 1       X = 2   Y = 3
  8. COUNT = 2       X = 2   Y = 4
  9. COUNT = 3       X = 2   Y = 5
  10. COUNT = 4       X = 3   Y = 2
  11. COUNT = 5       X = 3   Y = 3
  12. COUNT = 6       X = 3   Y = 4
  13. COUNT = 7       X = 4   Y = 3
  14. COUNT = 8       X = 5   Y = 3

  15. --------------------------------
  16. Process exited after 0.01647 seconds with return value 0
  17. 请按任意键继续. . .

复制代码
捕获.PNG

最佳答案

查看完整内容

# 太难了 # 链表忘了,又回去复习了一下 # 代码很糟糕 result:
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-8-21 21:35:35 | 显示全部楼层    本楼为最佳答案   
# 太难了
# 链表忘了,又回去复习了一下
# 代码很糟糕
  1. #include<stdio.h>
  2. #include<malloc.h>

  3. #define N 6

  4. typedef struct ZERO //标记不被包围 0 的位置
  5. {
  6.         int count;
  7.         int x;
  8.         int y;
  9.         struct ZERO *next;
  10. } *ZEROP;

  11. int adjacent_to_zero(ZEROP head, ZEROP point); //检查是否与不被包围 0 相邻
  12. void print_struct(ZEROP, char*);
  13. ZEROP pop(ZEROP*, int n, int*);
  14. int main(void)
  15. {
  16.         int arr[N][N] = { 1, 1, 1, 1, 1, 1,
  17.                                           1, 1, 0, 0, 0, 1,
  18.                                           1, 0, 0, 0, 1, 0,
  19.                                           1, 1, 0, 1, 1, 1,
  20.                                           0, 1, 0, 1, 0, 0,
  21.                                           1, 1, 1, 1, 1, 1};
  22.        
  23.         int i = 0;
  24.         int j = 0;
  25.         int count = 0;
  26.         char un_zero_str[20] = "被包围 0";
  27.         char zero_str[20] = "不被包围 0";
  28.         ZEROP head, pn, pend; // head 不被包围 0 的位置头指针
  29.         ZEROP un_head, un_pn, un_pend; // un_head 未知不被包围 0 的位置头指针
  30.         ZEROP temp = NULL;
  31.         for (i=0; i<N; i++) // 查找最外层有没有 0
  32.         {
  33.                 for (j=0; j<N; j++)
  34.                 {
  35.                         if (i == 0 || i == N-1 || j == 0 || j == N-1)
  36.                                 {
  37.                                         if (!arr[i][j])
  38.                                         {
  39.                                                 if (count == 0)
  40.                                                 {
  41.                                                         head = malloc(sizeof(struct ZERO));
  42.                                                         head->x = i;
  43.                                                         head->y = j;       
  44.                                                         head->next = NULL;
  45.                                                         pn = pend = head;
  46.                                                         count++;
  47.                                                         head->count = count;
  48.                                                 }
  49.                                                 else
  50.                                                 {
  51.                                                         count++;
  52.                                                         pend = malloc(sizeof(struct ZERO));
  53.                                                         pn->next = pend;
  54.                                                         pend->count = count;
  55.                                                         pend->x = i;
  56.                                                         pend->y = j;
  57.                                                         pend->next = NULL;
  58.                                                         pn = pend; //标记 1
  59.                                                        
  60.                                                 }
  61.                                                
  62.                                         }
  63.                                         continue;
  64.                                 }
  65.                 }
  66.         }
  67.         int find = 2;
  68.         if (!count) // 最外层没有 0 里面所有0都是被包围的0
  69.         {
  70.                 find = 0;
  71.         }
  72.         int mark = 0;
  73.         int un_count = 0;
  74.         for (i=1; i<N-1; i++)
  75.         {
  76.                 for (j=1; j<N-1; j++)
  77.                 {
  78.                         if (arr[i][j]) continue;
  79.                         temp = malloc(sizeof(struct ZERO));
  80.                         temp->x = i;
  81.                         temp->y = j;
  82.                         temp->next = NULL;
  83.                         if (!find) // 最外层没有 0
  84.                         {
  85.                                 if (count == 0)
  86.                                 {
  87.                                         head = temp;
  88.                                         head->next = NULL;
  89.                                         pn = pend = head;
  90.                                         count++;
  91.                                         head->count = count;
  92.                                         continue;
  93.                                 }
  94.                                 else
  95.                                 {
  96.                                         count++;
  97.                                         pn->next = temp;
  98.                                         temp->count = count;
  99.                                         pn = temp; //标记 1
  100.                                          
  101.                                 }
  102.                         }
  103.                         else if (adjacent_to_zero(head, temp)) // 最外层有 0
  104.                         {
  105.                                 un_count++;
  106.                                 if (!mark)
  107.                                 {
  108.                                         un_head = temp;
  109.                                         un_head->count = un_count;
  110.                                         un_pn = un_head;
  111.                                         mark = 1;
  112.                                         continue;
  113.                                        
  114.                                 }
  115.                                 un_pn->next = temp;
  116.                                 temp->count = un_count;
  117.                                 un_pn = temp;
  118.                         }
  119.                         else
  120.                         {
  121.                                 count ++;
  122.                                 pn->next = temp; //接着标记 1
  123.                                 temp->count = count;
  124.                                 pn = temp;
  125.                         }
  126.                 }
  127.         }
  128.         if (!find) // 最外层没有 0 直接打印结果
  129.         {
  130.                 print_struct(head, zero_str);
  131.                 return 0;
  132.         }
  133.         //print_struct(un_head, un_zero_str);
  134.         temp = un_head;
  135.         int one = 0;
  136.         while (1)
  137.         {
  138.                 one ++;
  139.                 if (! adjacent_to_zero(head, temp)) //将未知 0 转入不被包围的 0
  140.                 {
  141.                         count++;
  142.                         //转入后更新链表
  143.                         if (un_head->next)
  144.                                 temp = pop(&un_head, temp->count, &find);
  145.                         else find = 0;
  146.                         //print_struct(head, zero_str);
  147.                         //printf("count = %d\n", count);
  148.                         temp->count = count;
  149.                         pn->next = temp; //接着标记 1
  150.                         pn = temp;
  151.                         if (!find) break;
  152.                         if (find == 1)
  153.                         {
  154.                                 temp = un_head;
  155.                                 continue;
  156.                         }
  157.                 }
  158.                 //printf("one = %d\n", one);
  159.                 if (!temp->next) break;
  160.                 temp = temp->next;
  161.         }
  162.         //free(p);
  163.         print_struct(head, zero_str);
  164.         if (find)
  165.                 print_struct(un_head, un_zero_str);
  166.         return 0;
  167. }

  168. int adjacent_to_zero(ZEROP head, ZEROP point)
  169. {
  170.         while(1)
  171.         {
  172.                 if (head->x == point->x) //同一行
  173.                 {
  174.                         if (head->y == point->y-1 || head->y == point->y+1)
  175.                                 return 0;
  176.                 }
  177.                 if (head->y == point->y)
  178.                 {
  179.                         if (head->x == point->x+1 || head->x == point->x-1) //同一列
  180.                                 return 0;
  181.                 }
  182.                 if (head->next == NULL) break;
  183.                 head = head->next;
  184.         }
  185.         return 1;
  186. }

  187. void print_struct(ZEROP head, char* title)
  188. {
  189.         printf("%s:\n",title);
  190.         while (1)
  191.         {
  192.                 printf("COUNT = %d\tX = %d\tY = %d\n",head->count ,head->x+1 ,head->y+1);
  193.                 if (!head->next) break;
  194.                 head = head->next;
  195.         }
  196. }

  197. ZEROP pop(ZEROP* linked_list, int n, int* find)
  198. {
  199.         int count = 0;
  200.         ZEROP result, previous;
  201.         previous = result = *linked_list;
  202.         while (1)
  203.         {
  204.                 if (previous->count == n && count == 0)
  205.                 {
  206.                         *linked_list = previous->next;
  207.                         *find = 1;
  208.                         return previous;
  209.                 }
  210.                 else if (result->count == n)
  211.                 {
  212.                         previous->next = result->next;
  213.                         *find = 1;
  214.                         return result;
  215.                 }
  216.                 if (!result->next) break;
  217.                 previous = result;
  218.                 result = result->next;
  219.         }
  220.         *find = 2;
  221.         return result;
  222. }
复制代码

result:
  1. 不被包围 0:
  2. COUNT = 1       X = 3   Y = 6
  3. COUNT = 2       X = 5   Y = 1
  4. COUNT = 3       X = 5   Y = 6
  5. COUNT = 4       X = 5   Y = 5
  6. 被包围 0:
  7. COUNT = 1       X = 2   Y = 3
  8. COUNT = 2       X = 2   Y = 4
  9. COUNT = 3       X = 2   Y = 5
  10. COUNT = 4       X = 3   Y = 2
  11. COUNT = 5       X = 3   Y = 3
  12. COUNT = 6       X = 3   Y = 4
  13. COUNT = 7       X = 4   Y = 3
  14. COUNT = 8       X = 5   Y = 3

  15. --------------------------------
  16. Process exited after 0.01647 seconds with return value 0
  17. 请按任意键继续. . .

复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-8-22 08:40:28 | 显示全部楼层
/*
1 代表海岸线,0 代表小岛。求小岛面积(即被 1 中包围的 0 的个数)。
注意:仅求这样的 0,该 0 所在行中被两个 1 包围,该 0 所在列中被两个
*/

#include <stdio.h>
#include <stdlib.h>
#define N 6 // 假设是6维的方阵

void input(int (*arr)[N]);
int check(int (*arr)[N], int row, int col);

int main(void)
{
                int i, j;
                int count = 0;
                int arr[N][N] = {0};

                input(arr);

                // 由题意知,小岛在矩阵边缘不属于小岛面积
                for(i = 0; i < N; i++)    //问题 1
                {
                        for(j = 0; j < N; j++)//问题2
                        {
                                // 只判断是小岛周围
                                if(arr[i][j] == 0)
                                {
                                        if(check(arr, i, j)) // 如果检查后满足条件,小岛面积加1
                                        {
                                                count++;
                                        }
                                }
                        }
                }

                printf("小岛面积为%d\n",count);
                system("pause");
                return 0;
}

void input(int (*arr)[N])
{
                int i, j;

                for(i = 0; i < N; i++)
                {
                        for(j = 0; j < N; j++)
                        {
                                scanf("%d",&arr[i][j]); // 只能输入0或1
                                if(arr[i][j] != 0 && arr[i][j] != 1)
                                {
                                        printf("输入错误,退出程序");
                                        exit(1);
                                }
                        }
                }
}

// 判断是否符合题目要求
int check(int (*arr)[N], int row, int col)
{
                int h, l, m, n;
                m = n = 0;

                // 检查行
                for(h = row, l = col; l >= 0; l--)
                {
                        if(arr[h][l] == 1)
                        {
                                for(h = row, l = col; l < N; l++)
                                {
                                        if(arr[h][l] == 1)
                                        {
                                                n++; // 都满足,n+1
                                                break;
                                        }
                                }
                                if(n == 1)
                                {
                                        break;
                                }
                        }
                }

                // 检查列
                for(h = row, l = col; h >= 0; h--)
                {
                        if(arr[h][l] == 1)

                                for(h = row, l = col; h < N; h++)
                                {
                                        if(arr[h][l] == 1)
                                        {
                                                m++; // 都满足,m+1
                                                break;
                                        }
                                }
                                if(m == 1)
                                {
                                        break;
                                }
                }

                if(m + n == 2) // 两个条件都成立
                {
                        return 1;
                }
                return 0;
}
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-8-22 08:41:58 | 显示全部楼层
大佬,你这是作业?我最近刚看c语言,还写不出这种程序
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2020-8-22 09:16:01 | 显示全部楼层
编程白痴· 发表于 2020-8-22 08:40
/*
1 代表海岸线,0 代表小岛。求小岛面积(即被 1 中包围的 0 的个数)。
注意:仅求这样的 0,该 0  ...

没得反应啊,而且我感觉矩阵的最外面不需要判断,因为肯定不符合题意
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2020-8-22 09:16:31 | 显示全部楼层
编程白痴· 发表于 2020-8-22 08:41
大佬,你这是作业?我最近刚看c语言,还写不出这种程序

没事找的题
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-8-22 11:50:04 | 显示全部楼层
我觉得边界上的 0 应该算,如:arr[4][0] 和 arr[2][5],不在边界上的0不算,如:arr[4][4]
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2020-8-22 12:34:17 | 显示全部楼层
风过无痕1989 发表于 2020-8-22 11:50
我觉得边界上的 0 应该算,如:arr[4][0] 和 arr[2][5],不在边界上的0不算,如:arr[4][4]

但是小岛在边上的话,最多只能被3个海岸线包围啊,和题目上的不一样
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-8-23 07:56:37 | 显示全部楼层
111111
110000
100011
100000
111111
遇到这种情况怎么算?
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2020-8-23 08:57:34 | 显示全部楼层

加粗的三个呗
111111
110000
100011
100000
111111
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-8-23 09:22:42 | 显示全部楼层
巴巴鲁 发表于 2020-8-23 08:57
加粗的三个呗
111111
110000

懂了
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-8-23 10:01:29 | 显示全部楼层
巴巴鲁 发表于 2020-8-23 08:57
加粗的三个呗
111111
110000

加粗的三个,也没有被完全封闭,它们上面与下面都是0,所以,还得考虑边界上的0才行
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2020-8-23 10:10:34 | 显示全部楼层
风过无痕1989 发表于 2020-8-23 10:01
加粗的三个,也没有被完全封闭,它们上面与下面都是0,所以,还得考虑边界上的0才行

我理解的是只要0所在行左右,所在列上下有1就行了
你看看那个输出输入样例
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2020-8-23 19:37:32 | 显示全部楼层
Cool_Breeze 发表于 2020-8-23 15:31
# 太难了
# 链表忘了,又回去复习了一下
# 代码很糟糕

强,让我好好研究研究
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-7-1 11:01

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表