日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

网易2022秋季校园招聘-通用技术A卷-0918

發布時間:2024/10/5 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 网易2022秋季校园招聘-通用技术A卷-0918 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

https://gitee.com/shentuzhigang/algorithm/tree/master/exam-netease/exam-netease-20210918

編程題

第一題

解決方案

JAVA

import java.util.Scanner;/*** @author ShenTuZhiGang* @version 1.0.0* @email 1600337300@qq.com* @date 2021-09-18 18:03*/ public class ExamNetEase2021091801 {public static void main(String[] args) {Scanner scanner = new Scanner(System.in);int n = scanner.nextInt();String str = String.valueOf(n);int count = 0;for (int i = 0; i < str.length(); i++) {if (str.charAt(i) != '0' && n % (str.charAt(i) - '0') == 0) {count++;}}System.out.println(count);} }

第二題

解決方案

JAVA

71%

import java.util.Scanner;/*** @author ShenTuZhiGang* @version 1.0.0* @email 1600337300@qq.com* @date 2021-09-18 18:03*/ public class ExamNetEase2021091802 {public static void main(String[] args) {Scanner scanner = new Scanner(System.in);String str = scanner.nextLine();String[] strings = str.split(" ");str = strings[0];int n = Integer.parseInt(strings[1]);int[] a = new int[str.length() - 1];long count = 0;long sum = 0;long max = 0;for (int i = 1; i < str.length(); i++) {int i1 = Math.abs(str.charAt(i) - str.charAt(i - 1));a[i - 1] = Math.min(26 - i1, i1);count += a[i - 1];sum += a[i - 1];if (i - 1 - n >= 0) {count -= a[i - 1 - n];max = Math.max(max, count);}}if (a.length > n) {System.out.println(Math.min(sum + str.length() - max + n, sum + str.length()));} else {System.out.println(sum + str.length());}} }

第三題

解決方案

JAVA

import java.util.Scanner;/*** @author ShenTuZhiGang* @version 1.0.0* @email 1600337300@qq.com* @date 2021-09-18 18:03*/ public class ExamNetEase2021091803 {public static void main(String[] args) {Scanner scanner = new Scanner(System.in);long n0 = scanner.nextLong();long n = n0;if (n == 0) {System.out.println(-1);return;}int count1 = 0, count2 = 0, num = 0;while (n != 0) {if (n % 2 == 1) {count1++;}num++;n /= 2;}long m = (long) (Math.pow(2, num) - n0);while (m != 0) {if (m % 2 == 1) {count2++;}m /= 2;}System.out.println(Math.min(count1, count2 + 1));} }

第四題

解決方案

JAVA

版本一

import java.util.Comparator; import java.util.PriorityQueue; import java.util.Scanner;/*** @author ShenTuZhiGang* @version 1.0.0* @email 1600337300@qq.com* @date 2021-09-18 18:03*/ public class ExamNetEase2021091804 {private static int n;private static int a;private static int b;private static int[][] ans;private static boolean flag = false;private static int[][] pos = new int[2][2];private static char[][] map;public static void main(String[] args) {Scanner scanner = new Scanner(System.in);n = scanner.nextInt();a = scanner.nextInt();b = scanner.nextInt();map = new char[n][n];ans = new int[n][n];pos[0][0] = -1;pos[0][1] = -1;pos[1][0] = -1;pos[1][1] = -1;int p = 0;scanner.nextLine();for (int i = 0; i < n; i++) {map[i] = scanner.nextLine().toCharArray();for (int j = 0; j < n; j++) {if (map[i][j] == '*') {pos[p][0] = i;pos[p][1] = j;flag = true;}ans[i][j] = Integer.MAX_VALUE;}}PriorityQueue<Node> q = new PriorityQueue<>(new Comparator<Node>() {@Overridepublic int compare(Node o1, Node o2) {return o1.count - o2.count;}});Node node = new Node();node.x = 0;node.y = 0;node.count = 0;q.add(node);while (q.size() > 0) {node = q.poll();if (node.x >= n || node.y >= n || node.x < 0 || node.y < 0 || node.count > ans[n - 1][n - 1]) {continue;}if (ans[node.x][node.y] > node.count) {ans[node.x][node.y] = node.count;} else {return;}int c1 = 0;if (map[node.x][node.y] == '#') {c1 = a;} else if (map[node.x][node.y] == '*') {Node node1 = new Node();if (node.x == pos[0][0] && node.y == pos[0][1]) {node1.x = pos[1][0];node1.y = pos[1][1];} else {node1.x = pos[0][0];node1.y = pos[0][1];}node1.count = node.count + b;q.add(node1);}dfs(q, node.x + 1, node.y, node.count + c1);dfs(q, node.x, node.y + 1, node.count + c1);dfs(q, node.x - 1, node.y, node.count + c1);dfs(q, node.x, node.y - 1, node.count + c1);}System.out.println(ans[n - 1][n - 1]);}public static void dfs(PriorityQueue<Node> q, int x, int y, int count) {Node node1 = new Node();node1.x = x;node1.y = y;node1.count = count;q.add(node1);}static class Node {int x;int y;int count;} }

版本二
超時

import java.util.Scanner;/*** @author ShenTuZhiGang* @version 1.0.0* @email 1600337300@qq.com* @date 2021-09-18 18:03*/ public class ExamNetEase2021091804_2_TIMEOUT {private static int n;private static int a;private static int b;private static int[][] ans;private static boolean flag = false;private static int[][] pos = new int[2][2];private static char[][] map;public static void main(String[] args) {Scanner scanner = new Scanner(System.in);n = scanner.nextInt();a = scanner.nextInt();b = scanner.nextInt();map = new char[n][n];ans = new int[n][n];pos[0][0] = -1;pos[0][1] = -1;pos[1][0] = -1;pos[1][1] = -1;int p = 0;scanner.nextLine();for (int i = 0; i < n; i++) {map[i] = scanner.nextLine().toCharArray();for (int j = 0; j < n; j++) {if (map[i][j] == '*') {pos[p][0] = i;pos[p][1] = j;flag = true;}ans[i][j] = Integer.MAX_VALUE;}}dfs(0, 0, 0);System.out.println(ans[n - 1][n - 1]);}public static void dfs(int x, int y, int count) {if (x >= n || y >= n || x < 0 || y < 0 || count > ans[n - 1][n - 1]) {return;}if (ans[x][y] > count) {ans[x][y] = count;} else {return;}int c1 = 0;if (map[x][y] == '#') {c1 = a;} else if (map[x][y] == '*') {if (x == pos[0][0] && y == pos[0][1]) {dfs(pos[1][0], pos[1][1], count + b);} else {dfs(pos[0][0], pos[0][1], count + b);}}dfs(x + 1, y, count + c1);dfs(x, y + 1, count + c1);dfs(x - 1, y, count + c1);dfs(x, y - 1, count + c1);} }

問答題

總結

以上是生活随笔為你收集整理的网易2022秋季校园招聘-通用技术A卷-0918的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。