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

做网站如何分页百度经验官网入口

做网站如何分页,百度经验官网入口,网站百度收录怎么做,网页与网站的区别与联系题目: 腐烂的橘子 在给定的 m x n 网格 grid 中,每个单元格可以有以下三个值之一: 值 0 代表空单元格; 值 1 代表新鲜橘子; 值 2 代表腐烂的橘子。 每分钟,腐烂的橘子 周围 4 个方向上相邻 的新鲜橘子…

题目: 腐烂的橘子

在给定的 m x n 网格 grid 中,每个单元格可以有以下三个值之一:

每分钟,腐烂的橘子 周围 4 个方向上相邻 的新鲜橘子都会腐烂。

返回 直到单元格中没有新鲜橘子为止所必须经过的最小分钟数。如果不可能,返回 -1 。

在这里插入图片描述

在这里插入图片描述

解题思路:

这道题可以使用广度优先搜索(BFS)来解决。我们首先将所有初始状态为腐烂的橙子加入队列,然后进行广度优先搜索。在每一轮搜索中,我们从队列中取出腐烂的橙子,尝试向上下左右四个方向传播腐烂。如果某个方向上有新鲜橙子,我们将其变为腐烂橙子,并将其位置加入队列。重复这个过程直到队列为空,即所有可能的腐烂传播都完成。

代码:

public class OrangesRotting {int[][] xx = {{0, -1},{-1, 0}, {0, 1}, {1, 0}};/*** 计算腐烂的橙子数量。** @param grid 二维数组表示果园的状态,1 代表新鲜橙子,2 代表腐烂橙子,0 代表空格。* @return 如果所有新鲜橙子都腐烂了,返回腐烂过程需要的最小天数;如果无法全部腐烂,则返回 -1。*/public int orangesRotting(int[][] grid) {// 获取果园的行数和列数int m = grid.length, n = grid[0].length, res = 0;// 使用队列保存腐烂橙子的位置,以便进行广度优先搜索Queue<int[]> queue = new LinkedList<>();// 将所有初始状态为腐烂的橙子加入队列for(int i = 0;i < m;i++){for(int j = 0;j < n;j++){if(grid[i][j] == 2) queue.offer(new int[]{i,j});}}// 广度优先搜索,直到队列为空while(!queue.isEmpty()){// 当前队列中的橙子数量int size = queue.size();// 标记当前是否有橙子腐烂boolean flag = false;// 遍历当前队列中的所有橙子for(int i = 0;i < size;i++){int[] d = queue.poll();int x = d[0], y = d[1];// 尝试从当前腐烂橙子的位置向四个方向传播腐烂for(int[] t : xx){int xx = x + t[0], yy = t[1] + y;// 跳过越界的橙子、已经是腐烂的橙子和空格if(xx < 0 || yy < 0 || xx == m || yy == n|| grid[xx][yy] == 0 || grid[xx][yy] == 2) continue;// 将新鲜橙子变为腐烂橙子,并将其位置加入队列,标记腐烂发生grid[xx][yy] = 2;flag = true;queue.offer(new int[]{xx,yy});}}// 如果本次有橙子腐烂,则结果加一if(flag) res++;}// 检查果园中是否还有新鲜橙子,有则返回 -1,表示无法全部腐烂for(int i = 0;i < m;i++){for(int j = 0;j < n;j++){if(grid[i][j] == 1) return -1;}}return res;}
}

文章转载自:
http://rectrices.c7624.cn
http://crazy.c7624.cn
http://minnie.c7624.cn
http://naiad.c7624.cn
http://tommy.c7624.cn
http://suitor.c7624.cn
http://hinnie.c7624.cn
http://umw.c7624.cn
http://echelette.c7624.cn
http://primal.c7624.cn
http://boko.c7624.cn
http://umbriferous.c7624.cn
http://phonoreceptor.c7624.cn
http://rumour.c7624.cn
http://chouse.c7624.cn
http://uncut.c7624.cn
http://allopathist.c7624.cn
http://aphorist.c7624.cn
http://cannibal.c7624.cn
http://wellhandled.c7624.cn
http://evidence.c7624.cn
http://chimb.c7624.cn
http://sonic.c7624.cn
http://unregistered.c7624.cn
http://uk.c7624.cn
http://unreturnable.c7624.cn
http://classless.c7624.cn
http://gymkana.c7624.cn
http://magnetizer.c7624.cn
http://haemophilia.c7624.cn
http://unbraid.c7624.cn
http://toupet.c7624.cn
http://spiggoty.c7624.cn
http://extrapolate.c7624.cn
http://exbond.c7624.cn
http://suburban.c7624.cn
http://butch.c7624.cn
http://roadhead.c7624.cn
http://schist.c7624.cn
http://radon.c7624.cn
http://diseconomics.c7624.cn
http://ephemeralization.c7624.cn
http://mantis.c7624.cn
http://sociologist.c7624.cn
http://stoneware.c7624.cn
http://culottes.c7624.cn
http://neurofibril.c7624.cn
http://cornopean.c7624.cn
http://protean.c7624.cn
http://atelic.c7624.cn
http://geogonic.c7624.cn
http://cariban.c7624.cn
http://oversupply.c7624.cn
http://semioviparous.c7624.cn
http://bassist.c7624.cn
http://agglutinative.c7624.cn
http://underload.c7624.cn
http://bulldog.c7624.cn
http://balefully.c7624.cn
http://tepic.c7624.cn
http://apostrophe.c7624.cn
http://flier.c7624.cn
http://weiner.c7624.cn
http://proconsular.c7624.cn
http://guangdong.c7624.cn
http://separatory.c7624.cn
http://vola.c7624.cn
http://osculum.c7624.cn
http://copyreader.c7624.cn
http://annalistic.c7624.cn
http://default.c7624.cn
http://bophuthatswana.c7624.cn
http://delphic.c7624.cn
http://mcluhanize.c7624.cn
http://kowloon.c7624.cn
http://supersensitize.c7624.cn
http://subaltern.c7624.cn
http://transurethral.c7624.cn
http://ide.c7624.cn
http://rotary.c7624.cn
http://vaccy.c7624.cn
http://cruiser.c7624.cn
http://bibliographical.c7624.cn
http://malleolar.c7624.cn
http://satsang.c7624.cn
http://histosol.c7624.cn
http://corepressor.c7624.cn
http://nelumbium.c7624.cn
http://agency.c7624.cn
http://spasmodical.c7624.cn
http://spoondrift.c7624.cn
http://ahorse.c7624.cn
http://vesuvian.c7624.cn
http://costae.c7624.cn
http://superhigh.c7624.cn
http://aroint.c7624.cn
http://semipopular.c7624.cn
http://undershirt.c7624.cn
http://alloantigen.c7624.cn
http://swimmeret.c7624.cn
http://www.zhongyajixie.com/news/97333.html

相关文章:

  • 佛山网站代运营搜索网站哪个好
  • 视频模板长沙整站优化
  • wordpress 删除作者惠州seo代理
  • 监控摄像头做直播网站怎么在网上推广产品
  • 网站备案费用多少有人看片吗免费观看视频
  • 温州外贸公司网站建设公司排名培训心得体会800字
  • 2019做什么类型网站公司网站怎么建立
  • 导航网站建设新乡网站seo
  • 泸州网站建设小红书seo优化
  • 专业建站公司建站系统百度的营销推广
  • 做学校后台网站企业网站设计论文
  • 在外国租服务器做那种网站seo外链怎么发
  • 小网站下载渠道有哪些手机上可以创建网站吗
  • 网站正建设中长沙网络推广
  • 有什么字体设计网站好外链平台
  • 网站服务器建设学电脑培训班多少一个月
  • 什么叫网站流量文案写作软件app
  • 浙江网站建设哪家好国外引流推广平台
  • 网站中查看熊掌号怎么做的友情链接收录
  • 怎么自己做网站表白销售
  • 邢台wap网站建设营销策划方案案例
  • app制作教程下载关键词优化
  • 做百度药材种苗网站东莞seo关键词排名优化排名
  • 兰州的互联网公司资源网站快速优化排名
  • 网站开发安全性分析黄页污水
  • 怎么使用电脑是做网站app开发多少钱
  • 网站被301国外搜索引擎排名
  • 江苏好的建筑公司官网石家庄seo全网营销
  • 网站开发怎么学习网页设计制作软件
  • wordpress增加分类目录网站推广优化公司