#华为机考# 求华为机试 7.13 题解
全部评论
import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class Third { static int M, N, minDist = Integer.MAX_VALUE; static int[][] parArea; static int direc1[] = {-1, 1, 0, 0}, direc2[] = {0, 0, 1, -1}; static List<Integer[]> res = null; public static void main(String[] args) { Scanner cin = new Scanner(System.in); M = cin.nextInt(); N = cin.nextInt(); int i1 = cin.nextInt(); int j1 = cin.nextInt(); parArea = new int[M + 1][N + 1]; boolean[][] visited = new boolean[M + 1][N + 1]; for (int i = 1; i < M + 1; i++) { for (int j = 1; j < N + 1; j++) { parArea[i][j] = cin.nextInt(); } } List<Integer[]> path = new ArrayList<>(); dfs(i1, j1, path, 1, visited); if (res == null) { System.out.print(-1 + " " + -1); return; } for (int i = 0; i < res.size(); i++) { System.out.print(res.get(i)[0] + " " + res.get(i)[1]); if (i < res.size() - 1) System.out.print(" "); } } public static void dfs(int curI, int curJ, List<Integer[]> path, int dist, boolean[][] visited) { if (parArea[curI][curJ] == 3 || parArea[curI][curJ] == 2) return; if (parArea[curI][curJ] == 1) { path.add(new Integer[]{curI, curJ}); if (dist < minDist) { res = new ArrayList<>(path); minDist = dist; }else if (dist == minDist && path.get(path.size() - 1)[0] < res.get(res.size() - 1)[0]) { res = new ArrayList<>(path); } path.remove(path.size() - 1); return; } visited[curI][curJ] = true; path.add(new Integer[]{curI, curJ}); for (int i = 0; i < 4; i++) { int nextI = curI + direc1[i], nextJ = curJ +direc2[i]; if (nextI >= 1 && nextI <= M && nextJ >= 1 && nextJ <= N && !visited[nextI][nextJ]) { if ((i == 2 || i == 3) dfs(nextI, nextJ, path, dist + 1, visited); } } path.remove(path.size() - 1); visited[curI][curJ] = false; } }
1 回复 分享
发布于 2022-07-14 16:51
import java.util.*; public class First { public static void main(String[] args) { Scanner cin = new Scanner(System.in); int n = cin.nextInt(); int[] weight = new int[n]; int[] time = new int[n]; for (int i = 0; i < n; i++) { weight[i] = cin.nextInt(); } for (int i = 0; i < n; i++) { time[i] = cin.nextInt(); } int[] a = {100, 80, 60}; int index = 0; Map<Integer, List<Integer[]>> map = new HashMap<>(); for (int j = 0; j <= 60; j++) { if (index < time.length && j != time[index]) continue; if (map.containsKey(j)) { List<Integer[]> tmpM = map.get(j); for (Integer[] is: tmpM) a[is[1]] += weight[is[0]]; map.remove(j); } while (index < time.length && j >= time[index]) { if (a[0] >= weight[index]) { a[0] -= weight[index]; List<Integer[]> tmpM = map.get(30 + time[index]); if (tmpM == null) { List<Integer[]> list = new ArrayList<>(); list.add(new Integer[]{index, 0}); map.put(30 + time[index], list); }else{ tmpM.add(new Integer[]{index, 0}); } index++; } else if (a[1] >= weight[index]) { a[1] -= weight[index]; List<Integer[]> tmpM = map.get(30 + time[index]); if (tmpM == null) { List<Integer[]> list = new ArrayList<>(); list.add(new Integer[]{index, 1}); map.put(30 + time[index], list); }else{ tmpM.add(new Integer[]{index, 1}); } index++; } else if (a[2] >= weight[index]) { a[2] -= weight[index]; List<Integer[]> tmpM = map.get(30 + time[index]); if (tmpM == null) { List<Integer[]> list = new ArrayList<>(); list.add(new Integer[]{index, 2}); map.put(30 + time[index], list); }else{ tmpM.add(new Integer[]{index, 2}); } index++; } else { time[index]++; int tmp = index + 1; while (tmp < time.length && time[tmp] <= time[index]) { time[tmp] = time[index]; tmp++; } } } } int[] b = {100 - a[0], 80 - a[1], 60 - a[2]}; System.out.println(b[0] + " " + b[1] + " " + b[2]); } }
1 回复 分享
发布于 2022-07-14 20:46
兄弟华为秋招笔试已经开始了嘛?
1 回复 分享
发布于 2022-07-14 01:59
华为机试_笔经面经_牛客网 https://www.nowcoder.com/discuss/985083
点赞 回复 分享
发布于 2022-07-14 15:57

相关推荐

机械打工仔:有说的你怀疑一下就行了,直接问也太实诚了
点赞 评论 收藏
分享
Twilight_m...:表格简历有点难绷。说说个人看法: 1.个人基本情况里好多无意义信息,什么婚姻状况、健康状况、兴趣爱好、户口所在地、身份证号码、邮政编码,不知道的以为你填什么申请表呢。 2.校内实践个人认为对找工作几乎没帮助,建议换成和测开有关的项目,实在没得写留着也行。 3.工作经历完全看不出来是干什么的,起码看着和计算机没啥关系,建议加强描述,写点你在工作期间的实际产出、解决了什么问题。 4.个人简述大而空,看着像AI生成,感觉问题最大。“Python,C,C++成为我打造高效稳定服务的得力工具”、“我渴望凭借自身技术知识与创新能力,推动人工智能技术的应用发展,助力社会实现智能化转型”有种小学作文的美感。而且你确定你个人简述里写的你都会嘛?你AI这块写的什么“深入研究”,发几篇顶会的硕博生都不一定敢这么写。而且你AI这块的能力和软测也完全无关啊。个人简述建议写你对哪些技术栈、哪些语言、哪些生产工具的掌握,写的有条理些,而且最好是和测开强相关的。
点赞 评论 收藏
分享
评论
2
4
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务