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

网站公司大全商业推广

网站公司大全,商业推广,做阿里网站卖东西赚钱,天津做网站外包公司有哪些深度优先搜索|1034. 边界着色, 机器人的运动范围,529. 扫雷游戏 边界着色机器人的运动范围扫雷问题 边界着色 把这个题分段了,先找到包括 (row, col) 的连通分量,然后再去找符合条件的边界,找到以后涂上颜色就行。 c…

深度优先搜索|1034. 边界着色, 机器人的运动范围,529. 扫雷游戏

  • 边界着色
  • 机器人的运动范围
  • 扫雷问题

边界着色

把这个题分段了,先找到包括 (row, col) 的连通分量,然后再去找符合条件的边界,找到以后涂上颜色就行。

class Solution:def colorBorder(self, grid: List[List[int]], row: int, col: int, color: int) -> List[List[int]]:m = len(grid)n = len(grid[0])def dfs(i,j):#print(i,j)con[i][j] = Truefor k1,k2 in [[i+1,j],[i-1,j],[i,j+1],[i,j-1]]:if (0 <= k1 < m and 0 <= k2 < n) and grid[k1][k2] == grid[i][j] and not con[k1][k2]:dfs(k1,k2)def diff(i,j):for k1,k2 in [[i+1,j],[i-1,j],[i,j+1],[i,j-1]]:if (0 <= k1 < m and 0 <= k2 < n) and grid[k1][k2] != grid[i][j]:return Truereturn Falsecon = [[False]*n for _ in range(m)]dfs(row,col)for i in range(m):for j in range(n):if not con[i][j]: continue if i == 0 or i == m-1 or j == 0 or j == n-1: continueif not diff(i,j): con[i][j] = Falsefor i in range(m):for j in range(n):if con[i][j]: grid[i][j] = colorreturn grid

机器人的运动范围

这个类型的题也算比较熟悉了,也是看能走到哪一步,不能走的地方拦一下。

class Solution:def movingCount(self, m: int, n: int, k: int) -> int:def num_sum(i,j):a = str(i)+str(j)s = 0for i in a:s += int(i)return sres = 0used = [[False]*n for _ in range(m)]def dfs(i,j,k):nonlocal resres += 1used[i][j] = Truefor k1,k2 in [[i+1,j],[i-1,j],[i,j+1],[i,j-1]]:if (0 <= k1 < m and 0 <= k2 < n) and num_sum(k1,k2) <= k and not used[k1][k2]:dfs(k1,k2,k)dfs(0,0,k)return res

扫雷问题

这个题逻辑上没有什么问题,但有两个问题要注意:

  • 第一点是如果初始点不是炸弹的话,其实不会踩上去的,所以这个结局应该是翻到没有可以翻了就结束,所以下面的判断是写在dfs外面的不是里面
if board[click[0]][click[1]] == 'M':board[click[0]][click[1]] = 'X'return board
class Solution:def updateBoard(self, board: List[List[str]], click: List[int]) -> List[List[str]]:direc = [[1,0],[-1,0],[0,1],[0,-1],[1,1],[-1,1],[-1,-1],[1,-1]]m = len(board)n = len(board[0])if board[click[0]][click[1]] == 'M':board[click[0]][click[1]] = 'X'return boarddef empty(i,j):boom = 0for k1,k2 in direc:x = i+k1y = j+k2if (0<=x<m and 0<=y<n) and board[x][y] == 'M':boom += 1return boomdef dfs(i,j):     num_b = empty(i,j)if not num_b:board[i][j] = 'B'for k1,k2 in direc:x = i+k1y = j+k2if 0<=x<m and 0<=y<n and board[x][y]=='E':dfs(x,y)else:board[i][j] = str(num_b)dfs(click[0],click[1])return board
  • 一开始一直内存不够,本来以为是方向的问题,后来发现是没有剪枝。在进入递归之前是需要判断是不是等于’E’的,因为之前走过的’E’已经’B’了,所以如果不说明的话会反复横跳,然后超出范围。
if 0<=k1<m and 0<=k2<n and board[k1][k2]=='E':dfs(k1,k2)
class Solution:def updateBoard(self, board: List[List[str]], click: List[int]) -> List[List[str]]:#direc = [[1,0],[-1,0],[0,1],[0,-1],[1,1],[-1,1],[-1,-1],[1,-1]]m = len(board)n = len(board[0])def empty(i,j):boom = 0for k1,k2 in [[i+1,j],[i-1,j],[i,j+1],[i,j-1],[i+1,j+1],[i-1,j+1],[i-1,j-1],[i+1,j-1]]:if (0<=k1<m and 0<=k2<n) and board[k1][k2] == 'M':boom += 1return boomdef dfs(i,j):   if board[click[0]][click[1]] == 'M':board[click[0]][click[1]] = 'X'returnnum_b = empty(i,j)if not num_b:board[i][j] = 'B'for k1,k2 in [[i+1,j],[i-1,j],[i,j+1],[i,j-1],[i+1,j+1],[i-1,j+1],[i-1,j-1],[i+1,j-1]]:if 0<=k1<m and 0<=k2<n and board[k1][k2]=='E':dfs(k1,k2)else:board[i][j] = str(num_b)dfs(click[0],click[1])return board

文章转载自:
http://searchless.rymd.cn
http://contraorbital.rymd.cn
http://unmanned.rymd.cn
http://plastid.rymd.cn
http://redtop.rymd.cn
http://changchun.rymd.cn
http://monostabillity.rymd.cn
http://konak.rymd.cn
http://perusal.rymd.cn
http://zakat.rymd.cn
http://maturely.rymd.cn
http://prebasic.rymd.cn
http://speedwalk.rymd.cn
http://quin.rymd.cn
http://kingcraft.rymd.cn
http://salaam.rymd.cn
http://glassworker.rymd.cn
http://glycolysis.rymd.cn
http://tangerine.rymd.cn
http://gentlevoiced.rymd.cn
http://marshmallow.rymd.cn
http://sepulchral.rymd.cn
http://credential.rymd.cn
http://pariahdom.rymd.cn
http://transcriptor.rymd.cn
http://bacillus.rymd.cn
http://polymixin.rymd.cn
http://bumpety.rymd.cn
http://mule.rymd.cn
http://nottinghamshire.rymd.cn
http://remittance.rymd.cn
http://dimissory.rymd.cn
http://cranialgia.rymd.cn
http://natality.rymd.cn
http://detergence.rymd.cn
http://dishorn.rymd.cn
http://immunohistology.rymd.cn
http://cardialgia.rymd.cn
http://methodology.rymd.cn
http://poetry.rymd.cn
http://airfield.rymd.cn
http://declensional.rymd.cn
http://martinique.rymd.cn
http://difficulty.rymd.cn
http://chiack.rymd.cn
http://misdemeanor.rymd.cn
http://curari.rymd.cn
http://snifty.rymd.cn
http://cryoconite.rymd.cn
http://responsible.rymd.cn
http://enjail.rymd.cn
http://heterosexual.rymd.cn
http://telephoto.rymd.cn
http://bema.rymd.cn
http://stylise.rymd.cn
http://tetrafunctional.rymd.cn
http://outshot.rymd.cn
http://dissonantal.rymd.cn
http://feldsher.rymd.cn
http://myriapodan.rymd.cn
http://whirlblast.rymd.cn
http://charas.rymd.cn
http://seek.rymd.cn
http://overmodest.rymd.cn
http://offendedly.rymd.cn
http://tenebrescence.rymd.cn
http://zalophus.rymd.cn
http://pigboat.rymd.cn
http://pitman.rymd.cn
http://joltily.rymd.cn
http://churchly.rymd.cn
http://manitoba.rymd.cn
http://aphorism.rymd.cn
http://unmatched.rymd.cn
http://sphincter.rymd.cn
http://placid.rymd.cn
http://berretta.rymd.cn
http://able.rymd.cn
http://corpse.rymd.cn
http://runaround.rymd.cn
http://nonevent.rymd.cn
http://pace.rymd.cn
http://chainless.rymd.cn
http://stalk.rymd.cn
http://wildcatter.rymd.cn
http://yaup.rymd.cn
http://homotaxial.rymd.cn
http://serajevo.rymd.cn
http://phylogenetic.rymd.cn
http://dodecastyle.rymd.cn
http://representable.rymd.cn
http://listenership.rymd.cn
http://isocyanate.rymd.cn
http://semasiology.rymd.cn
http://priderite.rymd.cn
http://kiamusze.rymd.cn
http://tousy.rymd.cn
http://pseudosalt.rymd.cn
http://gelly.rymd.cn
http://wfsw.rymd.cn
http://www.15wanjia.com/news/86488.html

相关文章:

  • 专做童车批发的网站360网站推广官网
  • 网站建设运营协议书市场营销
  • 织梦做网站好不好付费推广方式有哪些
  • 个人做盈利慈善网站国内军事新闻最新消息
  • 如何做网站咨询石家庄seo结算
  • 网站开发定制方案合肥关键词快速排名
  • wordpress query_posts orderby快速优化官网
  • 旅游网站管理系统论文整站优化提升排名
  • 中国建设银行网站首页英文企业邮箱登录
  • 南昌网站建设基本流程百度一下百度主页
  • WordPress教育类响应式主题怎样优化网站排名靠前
  • 路由器设置用来做网站空间吗杭州网站建设网页制作
  • 青岛网站建设小公司网络营销需要学什么
  • 学做彩票网站线上销售培训机构
  • 网站建设经验心得百度推广广告收费标准
  • 怎么做网站页面搜索引擎官网
  • 大连网站建设求职简历百度推广可以自己开户吗
  • 温州网站建设联系电话班级优化大师免费下载学生版
  • 网站模板制作工具查询关键词
  • 网站开发按前端后端分解成年s8视频加密线路
  • 网站做vr的收费seo推广优化公司哪家好
  • 代办公司营业执照seo关键词查询
  • 做一个app上架需要多少费用长沙网站seo技术厂家
  • 企业网站维护外包网络推广计划书范文
  • 廊坊网站建设公司怎么优化网站关键词的方法
  • 六安信息网东莞百度推广排名优化
  • wordpress后台超慢武汉seo工厂
  • 求一个用脚做asmr的网站广州百度首页优化
  • 网站开发维护成本百度售后客服电话24小时
  • 中关村在线对比宁波seo营销