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

青岛网站推广系统外包公司简介

青岛网站推广系统,外包公司简介,专科网页设计实训报告,太原小程序制作200. 岛屿数量 200. 岛屿数量时间:O(mn);空间:O(min(m, n)),队列最大入队个数,可以想象从左上到右下,第一次入队1个,第二次出队1,入队2,第三次出队2,入队3……

200. 岛屿数量

  • 200. 岛屿数量
  • 时间:O(mn);空间:O(min(m, n)),队列最大入队个数,可以想象从左上到右下,第一次入队1个,第二次出队1,入队2,第三次出队2,入队3…
class Solution {
public:int dir[4][2] = {0, 1, 1, 0, 0, -1, -1, 0};  // 右,下,左,上int count = 0;int row;int column;void bfs(vector<vector<char>>& grid, int x, int y){queue<pair<int, int>>q;q.push({x, y});while(!q.empty()){auto t = q.front();q.pop();for(int i = 0; i < 4; i++){int new_x = t.first + dir[i][0], new_y = t.second + dir[i][1];if(new_x < 0 || new_x >= row || new_y < 0 || new_y >= column){continue;}if(grid[new_x][new_y] != '1'){continue;}grid[new_x][new_y] = '0';  // 访问q.push({new_x, new_y});}}}int numIslands(vector<vector<char>>& grid) {// bfsrow = grid.size(), column = grid[0].size();for(int i = 0; i < row; i++){for(int j = 0; j < column; j++){if(grid[i][j] == '1'){bfs(grid, i, j);++count;}}}return count;}
};

695. 岛屿的最大面积

  • 695. 岛屿的最大面积
  • 同上,bfs
class Solution {
public:int dir[4][2] = {0, 1, 1, 0, 0, -1, -1, 0};  // 右,下,左,上int ret = 0;int row;int column;int bfs(vector<vector<int>>& grid, int x, int y){grid[x][y] = 0;queue<pair<int, int>>q;q.push({x, y});int square = 1;while(!q.empty()){auto t = q.front();q.pop();for(int i = 0; i < 4; i++){int new_x = t.first + dir[i][0], new_y = t.second + dir[i][1];if(new_x < 0 || new_x >= row || new_y < 0 || new_y >= column){continue;}if(grid[new_x][new_y] != 1){continue;}grid[new_x][new_y] = 0;  // 访问++square;q.push({new_x, new_y});}}return square;}int maxAreaOfIsland(vector<vector<int>>& grid) {// bfsrow = grid.size(), column = grid[0].size();for(int i = 0; i < row; i++){for(int j = 0; j < column; j++){if(grid[i][j] == 1){int temp = bfs(grid, i, j);ret = max(ret, temp);}}}return ret;}
};

547. 省份数量

  • 547. 省份数量
  • 思路:修改bfs的访问
class Solution {
public:int count = 0;int row;int column;void bfs(vector<vector<int>>& grid, int x, int y){grid[x][y] = grid[y][x] = 0;queue<pair<int, int>>q;q.push({x, y});while(!q.empty()){auto t = q.front();q.pop();int new_x = t.first;for(int i = 0; i < column; i++){if(grid[new_x][i] == 0){continue;}grid[new_x][i] = grid[i][new_x] = 0;  // 访问q.push({i, new_x});}}}int findCircleNum(vector<vector<int>>& isConnected) {// bfsrow = isConnected.size(), column = isConnected[0].size();for(int i = 0; i < row; i++){for(int j = 0; j < column; j++){if(isConnected[i][j] == 1){bfs(isConnected, i, j);++count;}}}return count;}
};
http://www.yayakq.cn/news/568317/

相关文章:

  • 肇东网站建设软件公司网站建设
  • 易班网站的建设内容涿州网站建设公司
  • 宠物网站建设总结dedecms英文外贸网站企业模板下载
  • 网站建设总结心得正规大宗商品交易平台
  • 网站开发采购合同模板下载新零售商城系统开发
  • 网站建设的功能定位网站隐私条款模板
  • 柳州网站河北软件开发网站建设
  • 珠海网站空间注册网站建设数据库的链接
  • 做网站制作赚钱吗方又圆网站建设
  • 彩票网站开发注意事情网页设计学什么软件
  • 电子商务网站的开发流程wordpress 主题没有样式
  • 重庆网站建设seo公司网站建设_网站设计 app制作
  • 专门做mod的网站wordpress打开网站前动画
  • 海口手机版网站建设永州公司网站建设
  • 长沙招聘信息最新招聘seo引擎优化是什么
  • 网站建设流程是什么php网站开发linux
  • 网站无法访问的原因购物网站建设 属于信息系统管理与设计么
  • 百度网站内容推广型网站建设电话
  • 邻水建设局网站做淘宝代码的网站
  • 范县网站建设费用网站建设公司的案例
  • 新手建站教程报价单网站建设 摄影服务
  • 如何做建材团购网站今天上海新闻综合新闻
  • 常州知名网站建设公司h5编辑器免费版
  • c 网站开发的好处广州番禺最新消息
  • 门户网站网站制作广州app开发公司排名
  • 南充个人急售二手房江苏网站优化建站
  • 网站建设合同标准版主机如何做网站空间
  • 小何自助建站自己做的网站转成二维码
  • 二手网站模板国家排污许可网站台账怎么做
  • 网站的创建历程怎么写网络平台推广的好处