当前位置: 首页 > news >正文

北京视频网站建设市场营销推广策划方案

北京视频网站建设,市场营销推广策划方案,网站排名易下拉霸屏,教如何做帐哪个网站好前言 大家好,我是jiantaoyab,在下面的题目中慢慢体会floodFill算法,虽然是新的算法,但是用的思想和前面的文章几乎一样,代码格式也几乎一样,但不要去背代码 图像渲染 https://leetcode.cn/problems/flood…

前言

大家好,我是jiantaoyab,在下面的题目中慢慢体会floodFill算法,虽然是新的算法,但是用的思想和前面的文章几乎一样,代码格式也几乎一样,但不要去背代码

图像渲染

https://leetcode.cn/problems/flood-fill/

解析

image-20240311085056178

代码

可以看到代码这部分,是不是和前面的文章的挺像的

class Solution {int m, n;int pre_color;int dx[4] = {0,0,1,-1};int dy[4] = {1,-1,0,0};
public:void dfs(vector<vector<int>>& image, int sr, int sc, int color){image[sr][sc] = color;for(int d = 0; d < 4; d++){int x = sr + dx[d], y = sc + dy[d];if((x >= 0 && x < m) && (y >= 0 && y < n) &&  image[x][y] == pre_color){image[x][y] = color;dfs(image, x, y, color);}}}vector<vector<int>> floodFill(vector<vector<int>>& image, int sr, int sc, int color) {m = image.size(), n = image[0].size();pre_color = image[sr][sc];if(image[sr][sc] == color) return image;dfs(image, sr, sc, color);return image; }
};

岛屿数量

https://leetcode.cn/problems/number-of-islands/

解析

image-20240311101256605

代码

class Solution {int m, n;vector<vector<bool>> check;int dx[4]= {0, 0, 1, -1};int dy[4]= {1, -1, 0, 0};
public:void dfs(vector<vector<char>>& grid, int i, int j){check[i][j] = true; //从i,j位置来的for(int d = 0; d < 4; d++){int x = i + dx[d], y = j + dy[d];if((x >= 0 && x < m) && (y >= 0 && y < n)  && grid[x][y] == '1' && !check[x][y]){dfs(grid, x, y);}}}int numIslands(vector<vector<char>>& grid) {int m = grid.size(), n = grid[0].size();check = vector<vector<bool>> (m ,vector<bool>(n));int ret = 0;//把整个grid遍历一次for(int i = 0; i < m; i++){for(int j = 0; j < n; j++){//如果是一个岛屿而且是没有出现过的if(grid[i][j] == '1' && !check[i][j]){ret++;dfs(grid, i, j);}}}return ret;}
};

岛屿的最大面积

https://leetcode.cn/problems/ZL6zAn/

解析

大家看这个图就知道题目求的是什么了,比起上一题,多个统计数

image-20240311093330311

代码

class Solution {    int m, n;bool check[51][51];int dx[4] = {1,-1,0,0};int dy[4] = {0, 0,1,-1};int count;
public:void dfs(vector<vector<int>>& grid, int i, int j){count++;check[i][j] = true;for(int d = 0; d < 4; d++){int x = i + dx[d], y = j + dy[d];if(x >= 0 && x < m && y >= 0 && y < n && grid[x][y] == 1  && !check[x][y]){dfs(grid, x, y);}}}int maxAreaOfIsland(vector<vector<int>>& grid) {m = grid.size(), n = grid[0].size();int ret = 0;for(int i = 0; i < m; i++){for(int j = 0; j < n; j++){if(!check[i][j] && grid[i][j] == 1){count = 0;dfs(grid, i, j);ret = max(ret, count);}}}return ret;}
};

被围绕的区域

https://leetcode.cn/problems/surrounded-regions/

解析

image-20240311105332642

代码

class Solution {int m, n;int dx[4] = {0,0,1,-1};int dy[4] = {1,-1,0,0};
public:void dfs(vector<vector<char>>& board, int i, int j){board[i][j] = 'a';for(int d = 0; d < 4; d++){int x = i + dx[d], y = j + dy[d];if(x >= 0 && x < m && y >= 0 && y < n && board[x][y] == 'O'){dfs(board, x, y);}}}void solve(vector<vector<char>>& board) {m = board.size(), n = board[0].size();//把左右2列边界处理了for(int i = 0; i < m; i++){if(board[i][0] == 'O') dfs(board, i, 0);if(board[i][n-1] == 'O') dfs(board, i, n-1);}//把上下2行边界处理了for(int j = 0; j < n; j++){if(board[0][j] == 'O') dfs(board, 0, j);if(board[m-1][j] == 'O') dfs(board, m-1, j);}//还原 + 修改for(int i = 0; i < m; i++){for(int j = 0; j < n; j++){if(board[i][j] == 'a') board[i][j] = 'O';else if(board[i][j] == 'O') board[i][j] = 'X';}}}
};

太平洋大西洋水流问题

https://leetcode.cn/problems/pacific-atlantic-water-flow/

解析

image-20240311172851034

代码

class Solution {int m, n;int dx[4] = {1, -1, 0, 0};int dy[4] = {0,  0, 1, -1};
public:void dfs(vector<vector<int>>& heights, int i, int j, vector<vector<bool>>&check){check[i][j] = true;for(int d = 0; d < 4; d++){int x = i + dx[d], y = j + dy[d];if(x >= 0 && x < m && y >= 0 && y < n &&  !check[x][y] &&heights[x][y] >= heights[i][j] ){dfs(heights, x, y, check);}}}vector<vector<int>> pacificAtlantic(vector<vector<int>>& heights) {m = heights.size(), n = heights[0].size();vector<vector<bool>> pac(m, vector<bool>(n));vector<vector<bool>> atl(m, vector<bool>(n));//处理pacfor(int j = 0; j < n; j++) dfs(heights, 0, j, pac);for(int i = 0; i < m; i++) dfs(heights, i, 0, pac);//处理altfor(int j = 0; j < n; j++) dfs(heights, m - 1, j, atl);for(int i = 0; i < m; i++) dfs(heights, i, n - 1, atl);vector<vector<int>> ret;for(int i = 0; i < m; i++){for(int j = 0; j < n; j++){if(pac[i][j] && atl[i][j])ret.push_back({i, j});}}return ret;}
};

扫雷游戏

https://leetcode.cn/problems/minesweeper/

解析

image-20240311180338853

代码

class Solution {int dx[8] = {0, 0, -1, 1, 1, 1, -1 ,-1};int dy[8] = {1, -1, 0, 0, 1, -1, 1 ,-1};int m, n;
public:void dfs(vector<vector<char>>& board, int i, int j){int count = 0; //地雷个数//统计地雷个数for(int d = 0; d < 8; d++){int x = i + dx[d], y = j + dy[d];if(x >= 0 && x < m && y >= 0 && y < n && board[x][y] == 'M'){count++;}}//周围有地雷if(count){board[i][j] = count + '0';return ;}//周围没地雷展开else{board[i][j] = 'B';for(int d = 0; d < 8; d++){int x = i + dx[d], y = j + dy[d];if(x >= 0 && x < m && y >= 0 && y < n && board[x][y] == 'E'){dfs(board, x, y);}}}}vector<vector<char>> updateBoard(vector<vector<char>>& board, vector<int>& click) {m = board.size(), n = board[0].size();int x = click[0], y = click[1];//开局中地雷if(board[x][y] == 'M'){board[x][y] = 'X';return board;}dfs(board, x, y);return board;}
};
http://www.hkea.cn/news/240392/

相关文章:

  • 营销网站定制的优势成品网站源码的优化技巧
  • 高职学院网站建设方案广告制作
  • table表格 做的网站营销案例分析报告模板
  • pc端网站做移动适配教育培训机构管理系统
  • 页游传奇排行榜无锡seo优化公司
  • 广西南宁网站设计百度seo算法
  • 网站建设服务怎么样近期国内热点新闻事件
  • 阿里巴巴网站国际站建设seo托管服务
  • 企业网站优化之如何做需求分析网奇seo赚钱培训
  • 施工企业会计制度收入确认规定百度自然排名优化
  • 校园网站建设意义网络营销的特点有哪些
  • 内江做网站哪里便宜google搜索关键词热度
  • 福建省建设银行招聘网站网络推广员压力大吗
  • 动态网站订单怎么做搜索引擎优化营销
  • html5行业网站最近有哪些新闻
  • 做网站业务的怎么寻找客户在哪里打广告效果最好
  • 广东深圳seo服务内容
  • 做网站怎么备案网络服务有限公司
  • 网站主页特效欣赏百度官网下载电脑版
  • php mysql开发网站开发任何小说都能搜到的软件
  • the7 wordpress主题宁波seo外包费用
  • 云南建筑培训网seo刷点击软件
  • 男女做暖网站h5页面制作平台
  • 可以做puzzle的网站百度关键词排名提升工具
  • 竞网网站建设南宁网站seo大概多少钱
  • 114黄页信息网宝鸡seo培训
  • 东南亚做棋牌网站挖掘爱站网
  • 中国工程建设招标网官方网站谷歌查询关键词的工具叫什么
  • wordpress管理员密码忘记成都seo招聘
  • 武汉企业建站系统模板下载官方正版百度