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相关推荐

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

    源代码:https://gitee.com/shentuzhigang/algorithm/tree/master/exam-netease/exam-netease-20210821 编程题 第一题 ...

  2. 网易 2019 秋季校园招聘编程题真题集合

    网易 2019 秋季校园招聘编程题真题集合 第一题 俄罗斯方块 问题描述 小易有一个古老的游戏机,上面有着经典的游戏俄罗斯方块.因为它比较古老,所以规则和一般的俄罗斯方块不同. 荧幕上一共有 n 列, ...

  3. 深信服2023秋季校园招聘C++笔试A卷

    深信服2023秋季校园招聘C++笔试 目录 前言 编程题目 第一题 第二题 第三题 目录 前言 题目类型: 不定项选择 填空题 编程题 这里只记录编程题目 编程题目 第一题 题目描述: 给定一个字符串 ...

  4. 快手2019秋季校园招聘算法笔试A卷编程题 - 题解

    快手算法笔试题,两个动态规划,一个签到题.数据太恶心了,魔法深渊那题,没给模,后来是我自己根据结果猜出来的,模是100000000310000000031000000003,居然还不是常规的10000 ...

  5. 快手2019秋季校园招聘算法笔试B卷编程题 - 题解

    快手算法笔试题,一个签到题,一个动态规划,一个二分答案.其中二分答案有个数据有问题. 题目链接:点这儿. 字符串排序 题目 月神拿到一个新的数据集,其中每个样本都是一个字符串(长度小于100),样本的 ...

  6. Hulu 2022春季校园招聘来啦

    2022春季校园招聘来了! @2021&2022届毕业生 01 招聘职位 软件开发工程师 (后端) 软件开发工程师(前端) 算法工程师(机器学习方向) 02 招聘对象 2021&202 ...

  7. 【米哈游】2022春季校园招聘

    作者:咖喱吉吉 链接:[米哈游]2022春季校园招聘网申开始啦!校园大使内推_招聘信息_牛客网 来源:牛客网 在这里有超多业界顶尖游戏制作大牛,等你一起来创作最激动人心的面向未来的产品!快来加入我们一 ...

  8. 【2017秋季校园招聘笔经面经专题汇总】

    [2017秋季校园招聘笔经面经专题汇总] 2017秋招进行时,牛妹特意为大家开放2017秋招面经专栏,同时面经活动也正在进行中,欢迎大家参与~~活动详情戳:http://www.nowcoder.co ...

  9. 微软公司2007年秋季校园招聘在线宣讲会

    微软公司2007年秋季校园招聘在线宣讲会 系统公告:感谢大家对微软公司的关注!本次校园招聘在线宣讲会将于19:00准时开始,请各位同学耐心等待.(18:35:54) John Liu 说:大家好晚上好 ...

最新文章

  1. HDU-1394-Minimum Inversion Number
  2. idea swagger生成接口文档_spring boot集成Swagger-UI接口文档
  3. Qt Creator指定编辑器设置
  4. 快手基于 Apache Flink 的优化实践
  5. c语言 1 %3c%3c -253,结构体嵌套 姓名前后怎么输出两次??
  6. 微软认证学习资料大集合(软件+资料)
  7. Intel 64/x86_64/IA-32/x86处理器 - 通用指令(9/E) - 比特位操控指令(BMI1 BMI2)
  8. mac下hive-1.2.2-src版本的编译
  9. 小清新风高清壁纸,让你一天心情轻松!
  10. Jquery插件的编写和使用
  11. 许家印砸1000亿布局AI、量子计算等领域,但在科技圈只能算轻壕
  12. CentOS云主机安全之新增ssh登录账户、禁止ROOT登陆
  13. 九校联考-长沙市一中NOIP模拟总结
  14. 1.业务架构·应用架构·数据架构实战 --- 架构实践全景图
  15. 电子计算机的核心部件是哪三个,电子计算机三大核心部件 是什么
  16. 华为平板鸿蒙操作系统,华为平板 MatePad Pro 来了!首搭鸿蒙系统,与电脑“花样”协同…...
  17. 小白学java-JVM知识点总结
  18. 麻辣烫有几种类型?不同种麻辣烫怎么做
  19. [unity小游戏]小球运动初步制作1.0版
  20. 整合SpringBoot + MybatisPlus 搭建JAVA多模块项目基本骨架

热门文章

  1. 关于Jstree节点显示无法收缩的解决办法
  2. mysql数据库事件不执行_如何查看mysql事件是否执行
  3. java 判断一个数是正整数_【Java】P1075 质因数分解—关于数学方法在解题中的运用—(OJ:洛谷)...
  4. python怎样导出py文件_导出python模块(到字符串或py文件)
  5. iframe嵌套页面 跨域_跨域解决方案
  6. Linux 进程通信fifo,Linux 进程通信之FIFO的实现
  7. mysql5.5的方言_mysql方言问题
  8. mysql配置读写分离无效_MySQL数据库的同步配置+MySql 读写分离
  9. android编程读取sd卡txt文件,如何读取SD卡中的txt文件?
  10. 单调不减序列查询第一个大于等于_[力扣84,85] 单调栈