应该没我惨,我用的python,结果忘记python排序怎么传lambda函数了,第一题做了将近有1个小时中途想换回cpp,结果心乱了代码内存炸了,后面直接放弃了,心态炸裂,一步错步步错
点赞 1

相关推荐

昨天 18:04
已编辑
西安交通大学 Java
我是菜鸡。4道题一道都没有全对,0.95  0.4  0.975  0.95  与大厂无缘了不愧是拼都督,笔试都能感觉到卷了--------第二题的屎山代码import java.util.*;import java.io.*;public class Main{public static void main(String[] args) throws InterruptedException {Scanner sc=new Scanner(new BufferedInputStream(System.in));PrintWriter out=new PrintWriter(new BufferedOutputStream(System.out));int L=sc.nextInt(),C=sc.nextInt(),n=sc.nextInt();int[]ds=new int[n+1];int[]ps=new int[n+1];for(int i=0;i<n;i++){ds[i]=sc.nextInt();ps[i]=sc.nextInt();}ds[n]=L;ArrayDeque<Integer>w=new ArrayDeque<>();int next=C;int start=-1;int startC=C;long cost=0;boolean stop=false;for(int i=0;i<=n;i++){if(next>=ds[i]){while(!w.isEmpty()&&ps[w.getLast()]>=ps[i])w.removeLast();w.addLast(i);}else{int need=ds[i]-next;while(!w.isEmpty()&&need>0){int idx=w.getFirst();int space=(C-startC)+(ds[idx]-(start==-1?0:ds[start]));// 可以加的油=邮箱中剩余的空间=起点时邮箱不满的空间+从起点走到这里花的油if(space<=need){need-=space;next+=space;cost+=(long)space*ps[idx];startC=C;start=idx;w.removeFirst();}else{start=idx;startC=C-space+need;next+=need;cost+=(long)need*ps[idx];need=0;}}if(need>0){stop=true;break;}i--; // 这时候反悔加了油,但是当前的i处的加油站还没有加进来,再来一轮}}if(stop)out.println(-1);else out.println(cost);out.flush();out.close();sc.close();}}只记得样例1了20 10 34 59 215 6输出为24
拼多多集团-PDD笔试
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务