Three questions, 120 minutes, score = 100 + 200 + 300. You need to process the input yourself.
Who is Huawei?
Huawei is the world's leading provider of information and communication technology (ICT) solutions. It focuses on the ICT field and adheres to stability
Healthy operation, continuous innovation, open cooperation, and built an end-to-end platform in the fields of telecom operators, enterprises, terminals and cloud computing
To provide competitive ICT solutions and products for operator customers, enterprise customers and consumers
And services, and is committed to enabling the future information society and building a better connected world. At present, Huawei has more than 170000 employees
The company has employees and operates in more than 170 countries and regions around the world, serving more than one third of the world's population.
What have we brought to the world?
Create value for customers. Together with operators, Huawei has built more than 1500 networks around the world, helping the world surpass
One third of the population is connected. Huawei and enterprise customers work together to help with Open Cloud Computing and agile enterprise network
Strive to achieve efficient operation and agile innovation in the fields of Ping An City, finance, transportation and energy. Huawei smart terminal and smart hand
Machines are helping people enjoy high-quality digital work, life and entertainment experience.
Promote the sound development of the industry. Huawei advocates openness, cooperation and win-win results, and cooperates and innovates with upstream and downstream partners and friends
Expand industrial value and form a healthy industrial ecosystem. Huawei has joined more than 300 standards organizations, industrial alliances and
Open source community, with a total of 43000 proposals. We are oriented to emerging hot areas such as cloud computing, NFV/SDN, 5G and other industries
Partner division of labor and cooperation to promote the sustainable and sound development of the industry.
Promote economic growth. Huawei not only brings direct tax payment, employment promotion and industrial chain driving effects to the host country,
More importantly, create a digital engine through innovative ICT solutions, promote the digital transformation of all walks of life, and promote economic development
Economic growth to improve people's quality of life and well-being.
Promote sustainable social development. As a responsible corporate citizen, Huawei is committed to bridging the global digital divide; In the West
Non Ebola epidemic areas, Japan's tsunami nuclear leak, China's Wenchuan earthquake and other major disaster sites, we are well aware that there is no communication in front of the disaster
We chose to stick to the importance of faith; We have launched the "future seed" project around the world to provide opportunities for young students from all over the world
Opportunities for training and internship in China.
- Difference between maximum absolute values
Trees. Find a node and isolate it from the parent to become the root of the new tree. The goal is to maximize the difference between the two trees. Return the node that should be split. If there is a draw, return the node with a smaller index.
The input in the first line is n, indicating the total number of nodes. The second row is the value of all nodes. Then there is the node relationship, [parent, child].
input:
4
4 9 -7 -8
0 1
0 3
1 2
output: 3
Note that the left child must appear before the right child in the relationship.
public class Main { static int largestGap = 0; static int res = 100000; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); Node[] nodes = new Node[n]; boolean[] notRoot = new boolean[n]; for (int i = 0; i < n; i++) { int v = sc.nextInt(); nodes[i] = new Node(i, v); } while (sc.hasNextInt()) { int p = sc.nextInt(); int c = sc.nextInt(); Node par = nodes[p]; Node child = nodes[c]; notRoot[c] = true; if (par.left == null) par.left = child; else par.right = child; } Node root = null; for (int i = 0; i < n; i++) { if (!notRoot[i]) { root = nodes[i]; break; } } subtreeSum(root); findGap(root, 0); System.out.println(res); } private static void findGap(Node root, int parVal) { if (root == null) return; int left = 0; int right = 0; // System.out.printf("findgap(), root.id=%d, largestGap=%d, res=%d\n", root.idx, largestGap, // res); if (root.left != null) { left = root.left.sum; int leftgap = Math.abs(root.sum + parVal - 2 * left); // System.out.printf("left=%d, leftgap=%d\n", left, leftgap); if (leftgap > largestGap) { largestGap = leftgap; res = root.left.idx; } else if (leftgap == largestGap && root.left.idx < res) { res = root.left.idx; } } if (root.right != null) { right = root.right.sum; int rightgap = Math.abs(root.sum + parVal - 2 * right); // System.out.printf("right=%d, rightgap=%d\n", right, rightgap); if (rightgap > largestGap) { largestGap = rightgap; res = root.right.idx; } else if (rightgap == largestGap && root.right.idx < res) { res = root.right.idx; } } // System.out.printf("largestGap=%d, res=%d\n", largestGap, res); findGap(root.left, parVal + root.val + right); findGap(root.right, parVal + root.val + left); } private static int subtreeSum(Node root) { if (root == null) return 0; int left = subtreeSum(root.left); int right = subtreeSum(root.right); int s = left + right + root.val; root.sum = s; return s; } } class Node { int idx; int val; int sum; Node left; Node right; public Node(int i, int v) { idx = i; val = v; sum = 0; left = null; right = null; } }
- Plum blossom pile
The grid represents the number of steps that can be jumped. The first line is m,n, indicating the size of the chessboard. Find the minimum number of steps to the bottom right corner. If not, return - 1.
public class Main { public static void main(String[] args) { final int INF = 100*100*10+1; Scanner sc = new Scanner(System.in); String[] input = sc.nextLine().split(","); int m = Integer.parseInt(input[0]); if (m <= 0) { System.out.println("-1"); return; } int n = Integer.parseInt(input[1]); if (n <= 0) { System.out.println("-1"); return; } int[][] grid = new int[m][n]; int[][] dp = new int[m][n]; for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { grid[i][j] = sc.nextInt(); dp[i][j] = INF; } } dp[0][0] = 0; for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { if (grid[i][j] == 0) continue; // jump to right for (int k = 1; k <= grid[i][j]; k++) { if (j+k >= n) break; if (grid[i][j+k] == 0) continue; dp[i][j+k] = Math.min(dp[i][j+k], dp[i][j]+1); } // jump to bottom for (int k = 1; k <= grid[i][j]; k++) { if (i+k >= m) break; if (grid[i+k][j] == 0) continue; dp[i+k][j] = Math.min(dp[i+k][j], dp[i][j]+1); } } } if (dp[m-1][n-1] >= INF) { System.out.println("-1"); return; } System.out.println(dp[m-1][n-1]); } private static void print2d(int[][] arr) { int m = arr.length; for (int i = 0; i < m; i++) System.out.println(Arrays.toString(arr[i])); System.out.println(); } }
- Minimum compile time
Only 5% of the test case s have passed, and it's too late.
Different projects require different dependencies. The first line is the target project. After that, each line represents the project and compilation time that a project depends on. The format is [project name, compilation time, * dependent project]. Dependent projects must be completed first.
input:
module3
module1,10
module2,5
module3,10,module1,module2
output: 20
input:
module2
module2,10,module1
output: -1
input:
module2
module2,10,module1
module1,10,module2
output: -1
public class Main { static boolean valid = true; public static void main(String[] args) { Scanner sc = new Scanner(System.in); String goal = sc.nextLine().trim(); Map<String, Integer> duration = new HashMap(); Map<String, Set<String>> prereqs = new HashMap(); while (sc.hasNextLine()) { String[] input = sc.nextLine().split(","); int d = Integer.parseInt(input[1]); duration.put(input[0], d); Set<String> pre = new HashSet(); for (int i = 2; i < input.length; i++) pre.add(input[i]); prereqs.put(input[0], pre); } int res = getTime(goal, duration, prereqs, new HashSet()); if (!valid) System.out.println("-1"); else System.out.println(res); } private static int getTime(String cur, Map<String, Integer> duration, Map<String, Set<String>> prereqs, Set<String> seen) { if (!valid) return -1; if (!prereqs.containsKey(cur) || seen.contains(cur)) { valid = false; return -1; } seen.add(cur); Set<String> pres = prereqs.get(cur); int t = duration.get(cur); int front = 0; for (String pre: pres) { front = Math.max(front, getTime(pre, duration, prereqs, seen)); } return t+front; } }