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

做网站交易装备可以么成都网络推广外包

做网站交易装备可以么,成都网络推广外包,欧美风格的网站,网络营销推广的基本手段题目#xff1a; 宝宝和妈妈参加亲子游戏#xff0c;在一个二维矩阵#xff08;N*N#xff09;的格子地图上#xff0c;宝宝和妈妈抽签决定各自 的位置#xff0c;地图上每个格子有不同的Q糖果数量#xff0c;部分格子有障碍物。 游戏规则Q是妈妈必须在最短的时间 宝宝和妈妈参加亲子游戏在一个二维矩阵N*N的格子地图上宝宝和妈妈抽签决定各自  的位置地图上每个格子有不同的Q糖果数量部分格子有障碍物。 游戏规则Q是妈妈必须在最短的时间每个单位时间只能走一步到达宝宝的位置路上的 所有糖果都可以拿走不能走障碍物的格子只能上下左右走。 请问妈妈在最短到达宝宝位置的时间内最多拿到多少糖果优先考虑最短时间到达的情况下尽  可能多拿糖果。 输入描述 第一行输入为N, N标识二维矩阵的大小 之后N行每行有N个值表格矩阵每个位置的值 其中 - 3妈妈 - 2宝宝 - 1障碍 0糖果数0表示没有糖果但是可以走 输出描述 输出妈妈在最短到达宝宝位置的时间内最多拿到多少糖果行末无多余空格 备注 地图最大50*50 示例1 输入 4 3 2 1 -3 1 -1 1 1 1 1 -1 2 -2 1 2 3 输出 9 说明 此地图有两条最短路径Q可到宝宝位置, 都是最短路径6步但先向下再向左可以拿到9个糖 果 示例2 输入 4 3 2 1 -3 -1 -1 1 1 1 1 -1 2 -2 1 -1 3 输出 -1 说明 此地图妈妈无法到达宝宝位置 题解 图求最短路径采用BFS搜索关于BFS推荐观看BFS广搜解决迷宫问题_哔哩哔哩_bilibili 看完基本就清楚BFS算法原理了。 这题里面因为有糖果数目所以这边采用的方法是如果下一步能走到终点那么终点位置的visit[endx][endy]不设置为1.这样其他方案走到终点的话也能加入进队列里面。但是由于队列里面取首元素是终点的话那么就不会往下找了所以搜索记录的应该也都是比较短的路线。然后再依旧采用一个List记录到终点的步数一个Map记录到终点的步数和糖果数的结果。最后找到最少的步数对应的最多糖果数就可以了。 代码 import java.util.*;public class FindCandy {public static void main(String[] args) {Scanner sc new Scanner(System.in);int n Integer.valueOf(sc.nextLine());int nums[][] new int[n][n];int stratPosX Integer.MIN_VALUE;int stratPosY Integer.MIN_VALUE;int childPosX Integer.MIN_VALUE;int childPosY Integer.MIN_VALUE;int visited[][] new int[n][n];for (int i 0; i n; i) {String path[] sc.nextLine().split( );for (int j 0; j n; j) {visited[i][j] 0;nums[i][j] Integer.valueOf(path[j]);if (nums[i][j] -3) {stratPosX i;stratPosY j;visited[i][j] 1;}if (nums[i][j] -2) {childPosX i;childPosY j;}}}int[][] directions {{-1, 0}, {0, -1}, {1, 0}, {0, 1}};QueueSteps queue new LinkedList();Steps firstStep new Steps(stratPosX, stratPosY, 0, 0);visited[stratPosX][stratPosY] 1;Steps endStep new Steps(childPosX, childPosY, 0, 0);queue.offer(firstStep);ListInteger finalRoteSteps new ArrayList();MapInteger, ListInteger stepCandyMap new HashMap();boolean hasRoote false;while (!queue.isEmpty()) {Steps frontStep ((LinkedListSteps) queue).getFirst();if (frontStep.x endStep.x firstStep.y endStep.y) {hasRoote true;continue;}for (int i 0; i 4; i) {int newX frontStep.x directions[i][0];int newY frontStep.y directions[i][1];if (newX 0 newX n newY 0 newY n nums[newX][newY] ! -1 visited[newX][newY] 0) { // System.out.println(newX newX newY newY candy nums[newX][newY]);Steps nextStep new Steps();if (newX endStep.x newY endStep.y) {nextStep new Steps(newX, newY, frontStep.getStep() 1, frontStep.getCandy());queue.offer(nextStep);finalRoteSteps.add(nextStep.step);ListInteger candyList stepCandyMap.containsKey(nextStep.step) ? stepCandyMap.get(nextStep.step) :new ArrayList();if (!candyList.contains(nextStep.candy)) {candyList.add(nextStep.candy);}stepCandyMap.put(nextStep.step, candyList);hasRoote true;} else {nextStep new Steps(newX, newY, frontStep.getStep() 1, frontStep.getCandy() nums[newX][newY]);visited[newX][newY] 1;queue.offer(nextStep);}}}((LinkedListSteps) queue).pollFirst();}if (hasRoote) {Collections.sort(finalRoteSteps);ListInteger candys stepCandyMap.get(finalRoteSteps.get(0));Collections.sort(candys);System.out.println(candys.get(candys.size() - 1));} else {System.out.println(-1);}} }class Steps {int x;int y;int step;int candy;public Steps() {}public Steps(int x, int y, int step, int candy) {this.x x;this.y y;this.step step;this.candy candy;}public int getX() {return x;}public void setX(int x) {this.x x;}public int getY() {return y;}public void setY(int y) {this.y y;}public int getStep() {return step;}public void setStep(int step) {this.step step;}public int getCandy() {return candy;}public void setCandy(int candy) {this.candy candy;} }验证
http://www.hkea.cn/news/14547324/

相关文章:

  • 济南集团网站建设公司好厦门市建设区网站
  • 创建自己的免费网站做门户网站赚广告费
  • dede 网站地图 模块centos6安装wordpress
  • 深圳电信网络建站wordpress手机端m.
  • 黄冈网站推广软件有哪些3g 手机网站
  • 怎么做企业网站一级悬浮菜单家在深圳 龙岗
  • 河北省建设信息网站成都住房和城乡建设厅官网
  • 如何在网站后台做网页开放平台供稿人计划
  • 东莞市58同城招聘seo网络推广案例
  • 电脑网站拒绝连接怎么解决杭州网站制作公司排名
  • 江苏中粟建设工程有限公司网站大气金融投资企业网站模板
  • 安徽省公共资源交易中心网站龙岩做网站改版找哪家公司
  • 南宁市企业网站建设wordpress能恢复数据库吗
  • 昆明网站建设哪家公司好wordpress如何制作模板
  • 西安大雁塔附近酒店推荐山东网站建设SEO优化制作设计公司
  • 德阳移动网站建设做网站需要什么人
  • 架设网站flash不显示企业网站设计中应注意产品发布功能优化
  • 网站备案应该怎么做寿光住房和城乡建设局网站
  • 网站备案在哪查扬州市城乡建设局网站
  • 做网站 然后百度推广视频建设网站首页
  • 智能科普网站平台建设方案哈尔滨公告
  • 彩票网站该怎么建设制作公司网页平台
  • 怎么自己做网站备案2024年最新时事新闻
  • 外贸公司 网站龙岗南联网站建设公司
  • 卖童书的网站该怎么做网站区域名怎么注册吗
  • 网站建设需求方案网站开发展示
  • 网站开发图书系统前台模板自己学习做网站6
  • 免费个人网站建站申请一下网站后台设置关键字
  • 重庆市建设工程信息官网站广州十大传媒公司
  • 专业做网站公司怎么样小程序网站开发