网易互联网8.8笔试题目复盘分享(菜鸡只通过2.3)
第一题
取巧题,全拆2就行
坑点: 全换成long可以ac
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int res = 0;
for (int i = 0; i < n; i++) {
int a = sc.nextInt();
res += a/2;
}
System.out.println(res);
}
}
第二题
dp题 和买股票思路很像 莫名其妙发现的坑点 12点居然是am 改了ac不改65
public class Main { 2
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
while (T-- > 0) {
int n = sc.nextInt();
int[] a = new int[n];
int[] b = new int[n-1];
for (int i = 0; i < n; i++) {
a[i] = sc.nextInt();
}
for (int i = 0; i < n-1; i++) {
b[i] = sc.nextInt();
}
int[][] dp = new int[n][2];
// 0--当前的人不买 只能和下一个一起买 1--当前的人买单人票
dp[0][0] = 0;
dp[0][1] = a[0];
for (int i = 1; i < n; i++) {
dp[i][0] = dp[i-1][1];
dp[i][1] = Math.min(dp[i-1][0]+b[i-1], dp[i-1][1]+a[i]);
}
int sec = dp[n-1][1];
int min = sec/60;
sec %= 60;
String secstr = sec >= 10 ? String.valueOf(sec):"0"+ sec;
int hour = min/60;
min %= 60;
String minstr = min >= 10 ? String.valueOf(min):"0"+ min;
hour += 8;
String extra = "am";
if (hour > 12) {
hour -= 12;
extra = "pm";
} 12点算am吗?
String hourstr = hour >= 10 ? String.valueOf(hour):"0"+hour;
System.out.println(hourstr+":"+minstr+":"+secstr+" "+extra);
}
}
}
第三题据说是背包问题 正好没复习到 拉胯了
错误代码不贴了 贪心乱贪一通 过了30%
第四题 应该就是有向图找环的问题,但直接t了 辛辛苦苦写一通一份都不给
第四题 应该就是有向图找环的问题,但直接t了 辛辛苦苦写一通一份都不给
代码不贴了 ac0%
#笔试题目##网易#