废话不多说,直接上大疆前两道编程题的代码
第一次发帖,编辑器还不太会用,大家凑合着看
第一道题是喝咖啡debug题,直接模拟写出代码就行。
import java.util.*; public class Main{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { int N = sc.nextInt(); int X = sc.nextInt(); int A = sc.nextInt(); int bugTime = 0; //代表未喝咖啡前所需的debug总时间 for (int i = 0; i N; i++) { bugTime += sc.nextInt(); } int efficientTime = 60 * X * A;//efficientTime代表喝了咖啡后可以提升效率的debug时间 int realTime = 0; if (bugTime < effiecientTime){ int rest = bugTime % X; realTime = bugTime / X; System.out.println(rest > 0 ? realTime + 1 : realTime); } else if ((realTime = bugTime - efficientTime + efficientTime / A) <= 480) { //这种情况为,efficientTime < bugTime,但由于喝了咖啡后所需时间小于8小时,所以输出realTime System.out.println(realTime); } else { System.out.println(0); } } } }
#大疆##笔试题目#
//第二道题为多重背包问题,可以直接用时间复杂度为O(n^3)的方法做,不用转01背包,这道题就不细讲了import java.util.*;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);while (sc.hasNext()){int n = sc.nextInt();int m = sc.nextInt();int v,w,s;int[] f = new int[m+1];for (int i = 1; i < n + 1; i++) {v = sc.nextInt();w = sc.nextInt();s = sc.nextInt();for (int j = m; j >= 0; j--) {for (int k = 0; k <= s && k * v <= j; k++) {f[j] = Math.max(f[j], f[j - k * v] + k * w);}}}System.out.println(f[m]);}}}