700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > 0814-网易游戏雷火秋招Web后端开发工程师

0814-网易游戏雷火秋招Web后端开发工程师

时间:2019-06-05 03:37:28

相关推荐

0814-网易游戏雷火秋招Web后端开发工程师

0814-网易游戏雷火秋招Web后端开发工程师

编程题1

这道题恶心的是输入的处理,需要将这个各种方括号的玩意儿读出来,解析为ArrayList,想了一下还是有办法可以解决的,直接根据],分割每个宝箱的钥匙,然后去除一些无关字符就得到了每个宝箱的钥匙,并且数据类型是二维ArrayList

然后就是直接一个程序遍历解决问题,遍历的时候记个数,计算一下开启的宝箱数量,如果开启的数量刚好等于n,那么返回true,否则为false

import java.util.*;public class Main {public static void main(String[] args) {Scanner scanner = new Scanner(System.in);String res = scanner.nextLine();List<List<Integer>> boxs = getkeys(res);int n = boxs.size();boolean[] visited = new boolean[n];int cnt = 0;Queue<Integer> queue = new LinkedList<>();queue.add(0);while(!queue.isEmpty()) {int temp = queue.poll();if (!visited[temp]) {visited[temp] = true;cnt++;for (int i : boxs.get(temp)) {queue.add(i);}}}if (cnt == n)System.out.println("true");elseSystem.out.println("false");}public static List<List<Integer>> getkeys(String res) {List<List<Integer>> ans = new ArrayList<List<Integer>>();String[] boxs = res.substring(1, res.length()-2).split("],");for (String box: boxs) {box = box.substring(1, box.length());String[] ints = box.split(",");List<Integer> temp = new ArrayList<>();for (String i : ints) {if (!i.equals(""))temp.add(Integer.parseInt(i));}ans.add(temp);}return ans;}}

编程题2

这道题想来很久还是有点猪脑过载,算了,算了,放弃了

编程题3

本来以为递归会出现超时,但是好像没有。。

通过递归计算点在希尔伯特曲线的序号,然后计算两个序号的绝对值之差

import java.util.*;public class Solution {/*** 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可*** @param n int整型 方格矩阵Cn下标* @param x1 int整型 方格1在方格矩阵中的横坐标* @param y1 int整型 方格1在方格矩阵中的纵坐标* @param x2 int整型 方格2在方格矩阵中的横坐标* @param y2 int整型 方格2在方格矩阵中的纵坐标* @return long长整型*/public long solution (int n, int x1, int y1, int x2, int y2) {// write code herereturn Math.abs(f(n, x1, y1) - f(n, x2, y2));}public long f(int n, int x, int y) {if (n == 0)return 1;int m = 1 << (n-1);if (x <= m && y <= m)return f(n-1, y, x);if (x > m && y <= m)return 3L * m * m + f(n-1, m-y+1, m*2-x + 1);if (x < m && y > m)return 1L * m * m + f(n-1, x, y - m);return 2L * m * m + f(n - 1, x - m, y - m);}}

感觉凉凉

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。