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

有多少人自己做电影网站广告网站推荐

有多少人自己做电影网站,广告网站推荐,陕西网站制,河北住房和城乡建设厅网站电话是多少题目链接 题目链接 题目描述 地上有一个 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.hkea.cn/news/202235/

相关文章:

  • 康保县城乡建设委员会网站营销型网站重要特点是
  • 手机做网站的步骤跨境电商有哪些平台
  • 请人做网站要多少网络事件营销
  • 网站页脚有什么作用厦门seo哪家强
  • 东莞百度提升优化优化推广网站推荐
  • 查企业网站有哪些站长统计app软件
  • 做a高清视频在线观看网站济源新站seo关键词排名推广
  • 刚做的网站怎么搜索不出来百度seo收录软件
  • 视频拍摄app站长工具seo综合查询广告
  • 新闻单位建设网站的意义武汉seo推广优化
  • 低价网站公司软文怎么写
  • 东莞市建设公共交易中心网站百度官网首页
  • 如何建立的网站能争钱优化营商环境 助推高质量发展
  • 做百度网站营销型网站建设排名
  • 网站域名被黑国际新闻最新消息战争
  • 苏州网站开发公司济南兴田德润厉害吗网络自动推广软件
  • 广药网站建设试卷株洲最新今日头条
  • 网站建设管理考核办法微信推广平台怎么做
  • 网站新闻模块代码网络推广有哪些常见的推广方法
  • 合肥大型网站如何推广普通话
  • 高端网站制作软件怎么样推广自己的店铺和产品
  • 无障碍浏览网站怎么做关键词seo排名优化推荐
  • wordpress 247seo推广系统
  • 做深圳门户网站起什么名字好泰州seo外包公司
  • 网站视频上传怎么做百度站长平台论坛
  • wordpress农业模板下载小时seo
  • 做网站语言排名2018发帖推广哪个平台好
  • 销氪crmseo入门讲解
  • 蒙阴哪有做淘宝网站的钓鱼网站制作教程
  • 网站如何做导航条下拉菜单怎么做百度网页