废话不多说,直接上大疆前两道编程题的代码

第一次发帖,编辑器还不太会用,大家凑合着看

第一道题是喝咖啡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]);
}
}
}
#大疆##笔试题目#
全部评论
有第三题的吗?
点赞 回复 分享
发布于 2019-08-04 23:10
题目在这个帖子里https://www.nowcoder.com/discuss/216688
点赞 回复 分享
发布于 2019-08-04 23:00

相关推荐

这是什么操作什么意思,这公司我服了...
斯派克spark:意思是有比你更便宜的牛马了
点赞 评论 收藏
分享
frutiger:逆天,我家就安阳的,这hr咋能说3k的,你送外卖不比这工资高得多?还说大厂来的6k,打发叫花子的呢?这hr是怎么做到说昧良心的话的
找工作时遇到的神仙HR
点赞 评论 收藏
分享
05-27 14:57
西北大学 golang
强大的社畜在走神:27届真不用急,可以搞点项目、竞赛再沉淀沉淀,我大二的时候还在天天打游戏呢
投递华为等公司10个岗位
点赞 评论 收藏
分享
码农索隆:这种hr,建议全中国推广
点赞 评论 收藏
分享
评论
点赞
51
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务