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

社交网站怎么做网站改版意见方案

社交网站怎么做,网站改版意见方案,妇产医院,读取wordpress最新文章题目链接 题目链接 题目描述 地上有一个 m 行和 n列的方格,横纵坐标范围分别是 0∼m−1 和 0∼n−1。 一个机器人从坐标 (0,0) 的格子开始移动,每一次只能向左,右,上,下四个方向移动一格。 但是不能进入行坐标和列…

题目链接

题目链接

题目描述

地上有一个 m 行和 n列的方格,横纵坐标范围分别是 0∼m−1 和 0∼n−1。

一个机器人从坐标 (0,0) 的格子开始移动,每一次只能向左,右,上,下四个方向移动一格。

但是不能进入行坐标和列坐标的数位之和大于 k 的格子。

请问该机器人能够达到多少个格子?

注意:
0<=m<=50
0<=n<=50
0<=k<=100

样例1 输入:k=7, m=4, n=5 输出:20

样例2 输入:k=18, m=40, n=40 输出:1484

解释:当k为18时,机器人能够进入方格(35,37),因为3+5+3+7 = 18。
但是,它不能进入方格(35,38),因为3+5+3+8 = 19。

题目考察知识点

图论!
深搜or光搜
当前节点可以达到的节点为上下左右四个方向

解题代码

深搜dfs

递归实现

class Solution {// 深度优先// 在确定完是否满足条件后,[先加结果,然后标为已走],然后再进行dfsint result;// 可以走的方向int dir[][] = {{-1,0},{1,0},{0,1},{0,-1}};public int movingCount(int threshold, int rows, int cols){// 判断临界情况,也就是rows和cols都为0if(rows == 0 || cols == 0){return 0;}// 判断是否走过boolean[][] used = new boolean[rows][cols];result = 0;// 判断0,0是否符合条件if(!judge(0,0,threshold))   return 0;result ++;used[0][0] = true;dfs(0, 0, rows, cols, threshold, used);return result;}// 深度优先public void dfs(int inow, int jnow, int rows, int cols, int threshold, boolean[][] used){for(int i = 0; i < 4; i ++){int inext = inow + dir[i][0];int jnext = jnow + dir[i][1];if(inext >= 0 && inext < rows && jnext >=0 && jnext < cols){// 满足条件,才进行下一个dfsif(used[inext][jnext]==false && judge(inext, jnext, threshold)){result ++;used[inext][jnext] = true;dfs(inext, jnext, rows, cols, threshold, used);}}}}// 是否满足条件public boolean judge(int i, int j, int threshold){int now = 0;while(i != 0){now += i % 10;i = i / 10;}while(j != 0){now += j % 10;j = j / 10;}// 不满足if(now > threshold){return false;}else{return true;}}
}

注意注意!!!

  • used数组是必须要有的!标识一下当前哪些格子被判断过了
  • 判断临界条件
    • 特别是!哪个rows和cols都为0的情况
  • 判断完是否符合条件再去进行dfs更容易

广搜bfs

队列实现
队列不为空的时候一直循环
符合条件的进入队列

class Solution {// 广度优先// 在确定完是否满足条件后,[先加结果,然后标为已走],然后再进队列int result;// 可以走的方向int dir[][] = {{-1,0},{1,0},{0,1},{0,-1}};public int movingCount(int threshold, int rows, int cols){// 判断临界情况,也就是rows和cols都为0if(rows == 0 || cols == 0){return 0;}// 判断是否走过boolean[][] used = new boolean[rows][cols];result = 0;bfs(rows, cols, threshold, used);return result;}// 广度优先public void bfs(int rows, int cols, int threshold, boolean[][] used){Deque<int[]> deque = new LinkedList<>();if(judge(0, 0, threshold)){deque.push(new int[]{0, 0});used[0][0] = true;result ++;}while(!deque.isEmpty()){int[] now = deque.pop();int inow = now[0];int jnow = now[1];for(int i = 0; i < 4; i ++){int inext = inow + dir[i][0];int jnext = jnow + dir[i][1];if(inext >= 0 && inext < rows && jnext >=0 && jnext < cols){// 满足条件,才进入队列if(used[inext][jnext]==false && judge(inext, jnext, threshold)){result ++;used[inext][jnext] = true;deque.push(new int[]{inext, jnext});}}}}return;}// 是否满足条件public boolean judge(int i, int j, int threshold){int now = 0;while(i != 0){now += i % 10;i = i / 10;}while(j != 0){now += j % 10;j = j / 10;}// 不满足if(now > threshold){return false;}else{return true;}}
}
http://www.yayakq.cn/news/198589/

相关文章:

  • 珠海做网站公司株洲网站设计公司
  • 深圳团购网站设计公司医疗网站建设免费
  • 如何做一个网站设计家用电脑进行网站建设
  • 网站seo在线诊断分析网络运营推广合作
  • 溧阳网站建设公司无极电影网免费完整播放电视剧
  • 汕头网站快速排名提升在线设计系统
  • 阿里巴巴国际站运营教程优化网站seo
  • 网站迅速备案中国最新消息军事方面的
  • 汕头h5建站万网的网站代码怎么看
  • 人社网站和微信平台建设方案佛山门户网站建设公司
  • 南京网站建设 个人镇江本地网站
  • 大型服装商城网站建设国家企业官方网站查询系统
  • 音乐网站开发代码小学生网上学做辅导哪个网站好
  • 本地做的网站怎么放到网上去浙江建设信息港成绩查询栏
  • 优化网站公司价格是多少钱做代理需要自己的网站吗
  • 公司网站制作天强科技专业购物网站建设多少钱
  • 网站开发收费表某某公司电子商务网站建设与维护
  • 怎么修改网站网页的背景图片北京到信阳
  • 建行手机网站网址是多少钱做外贸的网站
  • 网站seo优化技能在线制作图片书
  • 临猗网站建设5118新媒体运营
  • 网站版面布局设计的原则公司做网站的
  • 做网站的 简历深圳定制网页
  • 主题公园网站建设方案哪里有做网站app的
  • 网站图标下载wordpress安装不了 404
  • 网站开发毕设wordpress解析完403
  • 浙江大学陈越做的刷题网站wordpress demo数据
  • 如何加强网站管理的队伍建设个人网站的需求分析
  • 美食网站的建设目的centos7怎么做网站服务器
  • 移动端网站开发 float软件开发设计制作网站下载