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

企业建站公司是干嘛的大企业网站制作及维护

企业建站公司是干嘛的,大企业网站制作及维护,专门网页制作工具有,网站字体加载不出来怎么办1、题目描述 【上班之路】 Jungle 生活在美丽的蓝鲸城,大马路都是方方正正,但是每天马路的封闭情况都不一样。 地图由以下元素组成: 1)”.” — 空地,可以达到; 2)”*” — 路障,不可达到; 3&a…

1、题目描述

【上班之路】
Jungle 生活在美丽的蓝鲸城,大马路都是方方正正,但是每天马路的封闭情况都不一样。
地图由以下元素组成:
1)”.” — 空地,可以达到;
2)”*” — 路障,不可达到;
3)”S” — Jungle的家;
4)”T” — 公司.
其中我们会限制Jungle拐弯的次数,同时Jungle可以清除给定个数的路障,现在你的任务是计算Jungle是否可以从家里出发到达公司。

【输入描述】
输入的第一行为两个整数t,c(0<=t,c<=100), t代表可以拐弯的次数,c代表可以清除的路障个数。
输入的第二行为两个整数n,m(1<=n,m<=100),代表地图的大小。
接下来是n行包含m个字符的地图。n和m可能不一样大。
我们保证地图里有S和T。

【输出描述】
输出是否可以从家里出发到达公司,是则输出YES,不能则输出NO。

【示例1】
输入

2 0
5 5
..S..
****.
T....
****.
.....

输出
YES

【示例2】
输入:

1 2
5 5
.*S*.
*****
..*..
*****
T....

输出: NO
说明:该用例中,至少需要拐弯1次,清除3个路障,所以无法到达

2、解题思路

首先找到S的位置,再利用回溯算法从S位置开始遍历上、下、左、右四个方向可到达的位置,当到达公司位置T则代表可以到达公司,所有方向都遍历完成都无法到达T则无法到达公司。

3、参考代码

方法一:

import java.util.Scanner;/*** @Author Long* @Date 2023/5/3 20:45*/
public class 上班之路 {private static final int[][] directions = {{0, 1, 1}, {0, -1, 2}, {1, 0, 3}, {-1, 0, 4}};private static int maxTurns, maxClears, rows, cols;private static String[][] matrix;public static void main(String[] args) {Scanner in = new Scanner(System.in);while (in.hasNext()) {// 处理输入maxTurns = in.nextInt();maxClears = in.nextInt();rows = in.nextInt();cols = in.nextInt();matrix = new String[rows][cols];char[][] chars = new char[rows][cols];for (int i = 0; i < rows; i++) {String string = in.next();matrix[i] = string.split("");chars[i] = string.toCharArray();}for (int i = 0; i < rows; i++) {for (int j = 0; j < cols; j++) {boolean[][] visited = new boolean[cols][rows];if ("S".equals(matrix[i][j])) {if (dfs(visited, i, j, 0, 0, 0)) {System.out.println("YES");return;} else {System.out.println("NO");return;}}}}System.out.println("NO");return;}}public static boolean dfs(boolean[][] visited, int x, int y, int turnsUsed, int clearsUsed, int lastDirection) {if ("T".equals(matrix[x][y])) {return true;}visited[x][y] = true;for (int[] direction : directions) {int curDirection = direction[2];int newX = x + direction[0];int newY = y + direction[1];boolean turnFlag = false;boolean breakFlag = false;if (newX >= 0 && newX < rows && newY >= 0 && newY < cols && !visited[newX][newY]) {if (lastDirection != 0 && lastDirection != curDirection) {if (turnsUsed + 1 > maxTurns) {continue;}turnFlag = true;}if ("*".equals(matrix[newX][newY])) {if (clearsUsed + 1 > maxClears) {continue;}breakFlag = true;}if (dfs(visited, newX, newY, turnsUsed + (turnFlag ? 1: 0), clearsUsed + (breakFlag ? 1 : 0), curDirection)) {return true;}}}return false;}
}

方法二:

import java.util.Scanner;/*** @Author * @Date 2023/5/3 20:45*/
public class 上班之路 {private static final int[][] directions = {{0, 1, 1}, {0, -1, 2}, {1, 0, 3}, {-1, 0, 4}};public static void main(String[] args) {Scanner in = new Scanner(System.in);while (in.hasNext()) {// 处理输入int t = in.nextInt();int c = in.nextInt();int n = in.nextInt();int m = in.nextInt();char[][] chars = new char[n][m];for (int i = 0; i < n; i++) {String string = in.next();chars[i] = string.toCharArray();}int sX = 0;int sY = 0;for (int i = 0; i < n; i++) {for (int j = 0; j < m; j++) {if (chars[i][j] == 'S') {sX = i;sY = j;break;}}if (chars[sX][sY] == 'S') {break;}}boolean[][] used = new boolean[n][m];if (chars[sX][sY] == 'S') {if (dfs(chars, sX, sY, t, c, 0, used)) {System.out.println("YES");} else {System.out.println("NO");}} else {System.out.println("NO");}}}public static boolean dfs(char[][] chars, int x, int y, int t, int c, int dis, boolean[][] used) {int n = chars.length;int m = chars[0].length;if (x < 0 || x >= n || y < 0 || y >= m) {return false;}if (chars[x][y] == 'T') {return true;}used[x][y] = true;for (int i = 0; i < directions.length; i++) {int newX = x + directions[i][0];int newY = y + directions[i][1];// 超过边界if (newX < 0 || newX >= n || newY < 0 || newY >= m || used[newX][newY]) {continue;}if (chars[newX][newY] == '*') {  // 当前是障碍if (c == 0) {  // 清除障碍数用完了continue;}if (dis == 0 || dis == directions[i][2]) {if (dfs(chars, newX, newY, t, c - 1, dis, used)) {return true;}} else {  // 上一步方向跟当前方向不一致if (t == 0) {  // 拐弯数用完continue;}if (dfs(chars, newX, newY, t - 1, c - 1, dis, used)) {return true;}}} else {if (dis == 0 || dis == directions[i][2]) {if (dfs(chars, newX, newY, t, c, dis, used)) {return true;}} else {if (t == 0) {continue;}if (dfs(chars, newX, newY, t - 1, c, dis, used)) {return true;}}}}used[x][y] = false;return false;}}

4、相似题目

(1)西天取经
(2)士兵突击

http://www.yayakq.cn/news/274700/

相关文章:

  • 做网站广告多少钱跨国浏览器
  • 手机网站页面设计要求海南千筑建设工程有限公司网站
  • 商城和营销型网站建设免费交友软件
  • 旅游门户网站方案dnsprefetch wordpress
  • 哈尔滨寸金网站建设价格网站制作怎样做
  • 顺德网站建设公司有哪些建立网站一般包括什么等方式
  • 网站建设费用摊销多少年专业的logo设计
  • 做淘宝客必须有网站吗云主机服务器
  • 广州大型网站制作公司电子商务网站推广案例
  • 玉溪网站建设现状苏州企业网站制作电话
  • 权威发布的意思是什么seo专业培训学费多少钱
  • 医疗网站建设行情怎么开微商城网店步骤
  • 黔江做网站深圳广告网站设计制作
  • 建立网站一般要多少钱wordpress+手机端
  • 个人网站需要多大空间做网站图片属性
  • 大众点评做团购网站长沙的在线商城网站建设
  • 郑州企业网站优化哪家便宜网站访问统计怎么做
  • 织梦做网站详细教程百度怎么提交网站地图
  • 电子网站开发技术包括长沙房价2021新楼盘价格
  • 优质的网站建设网站 没有域名需要备案吗
  • 深圳大型网站设计公司域名解析后网站打不开
  • 大型网站 开发流程潍坊网站托管
  • 网站建设文件夹名字工作组赴哈尔滨
  • 网站点击弹出下载框 怎么做的什么是搜索引擎?
  • 揭阳网站定制香河住房和建设局网站
  • 商城微网站开发微网站信誉楼线上商城小程序
  • 做试题网站网站建设安全技术
  • 网站开发培训程序员济阳做网站多少钱
  • 网站开发付款分几步模具钢东莞网站建设
  • 做旅游网站多少钱投资公司注册资金需要多少