第二题~ class Node{ public int waitTIme; public int excTime; public int in ; } public class Main2 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); List<Node> wait =new LinkedList<>(); LinkedList<Node> exec =new LinkedList<>(); int size = scanner.nextInt(); for (int i = 0; i < size; i++) { Node node = new Node(); node.waitTIme = scanner.nextInt(); node.excTime = scanner.nextInt(); wait.add(node); } wait.sort(Comparator.comparingInt(a -> a.waitTIme)); int time = 0; while (wait.size() != 0 || exec.size() != 0) { time++; for (int i = 0; i < wait.size(); i++) { Node node = wait.get(i); if (time >= node.waitTIme) { wait.remove(node); node.in = time; exec.add(node); } } Node work = exec.peekFirst(); if (work != null) { if (time - work.in >= work.excTime) { exec.pop(); } } } System.out.println(time); } }
点赞 1

相关推荐

微风不断:兄弟,你把四旋翼都做出来了那个挺难的吧
点赞 评论 收藏
分享
牛客网
牛客企业服务