您的位置:首页 > 科技 > IT业 > python语言好学吗_设计衣服图制作软件_百度广告价格_整合营销名词解释

python语言好学吗_设计衣服图制作软件_百度广告价格_整合营销名词解释

2024/11/19 4:34:05 来源:https://blog.csdn.net/m0_59237910/article/details/142373379  浏览:    关键词:python语言好学吗_设计衣服图制作软件_百度广告价格_整合营销名词解释
python语言好学吗_设计衣服图制作软件_百度广告价格_整合营销名词解释

题目:

题解:

static const int dirs[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};void bfs(int row, int col, bool ** ocean, const int ** heights, int m, int n) {if (ocean[row][col]) {return;}ocean[row][col] = true;int * queue = (int *)malloc(sizeof(int) * m * n);int head = 0;int tail = 0;queue[tail++] = row * n + col;while (head != tail) {int row = queue[head] / n;int col = queue[head] % n;head++;for (int i = 0; i < 4; i++) {int newRow = row + dirs[i][0], newCol = col + dirs[i][1];if (newRow >= 0 && newRow < m && newCol >= 0 && newCol < n && heights[newRow][newCol] >= heights[row][col] && !ocean[newRow][newCol]) {ocean[newRow][newCol] = true;queue[tail++] = newRow * n + newCol;}}}free(queue);
}int** pacificAtlantic(int** heights, int heightsSize, int* heightsColSize, int* returnSize, int** returnColumnSizes){int m = heightsSize;int n = heightsColSize[0];bool ** pacific = (bool **)malloc(sizeof(bool *) * m);bool ** atlantic = (bool **)malloc(sizeof(bool *) * m);for (int i = 0; i < m; i++) {pacific[i] = (bool *)malloc(sizeof(bool) * n);atlantic[i] = (bool *)malloc(sizeof(bool) * n);memset(pacific[i], 0, sizeof(bool) * n);memset(atlantic[i], 0, sizeof(bool) * n);}for (int i = 0; i < m; i++) {bfs(i, 0, pacific, heights, m, n);}for (int j = 1; j < n; j++) {bfs(0, j, pacific, heights, m, n);}for (int i = 0; i < m; i++) {bfs(i, n - 1, atlantic, heights, m, n);}for (int j = 0; j < n - 1; j++) {bfs(m - 1, j, atlantic, heights, m, n);}int ** result = (int **)malloc(sizeof(int *) * m * n);*returnColumnSizes = (int *)malloc(sizeof(int) * m * n);int pos = 0;for (int i = 0; i < m * n; i++) {result[i] = (int *)malloc(sizeof(int) * 2);(*returnColumnSizes)[i] = 2;}for (int i = 0; i < m; i++) {for (int j = 0; j < n; j++) {if (pacific[i][j] && atlantic[i][j]) {result[pos][0] = i;result[pos][1] = j;pos++;}}free(pacific[i]);free(atlantic[i]);}free(pacific);free(atlantic);*returnSize = pos;return result;
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com