首页 > 猿辅导 服务器端开发 笔经(已凉)
头像
无情的offer收割机
编辑于 2020-08-08 17:32
+ 关注

猿辅导 服务器端开发 笔经(已凉)

2020.08.01 晚上 笔试 1h30min

1)小猿的时间管理

import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        PriorityQueue<int[]> queue = new PriorityQueue<>(new Comparator<int[]>() { @Override public int compare(int[] o1, int[] o2) {
                if(o1[0] != o2[0]) {
                    return o1[0] - o2[0];
                }
                else {
                    return o1[1] - o2[1];
                }
            }
        });
        for(int i = 0; i < n; i++){
            int[] a = new int[2];
            for(int j = 0; j < 2; j++){
                a[j] = sc.nextInt();
            }
            queue.add(a);
        }

        int res = 1;
        while(!queue.isEmpty()) {
            int[] first = queue.poll();
            if(queue.isEmpty()) {
                break;
            }
            int[] second = queue.peek();

            if(second[0] < first[1]) {
                res++;
                int[] tmp = new int[2];
                tmp[0] = second[0];
                tmp[1] = first[1];
                queue.poll();
                queue.add(tmp);
            }
        }

        System.out.println(res);
    }
}


第一题0,第二题没做,第三题没做,菜到怀疑人生。

全部评论

(2) 回帖
加载中...
话题 回帖

推荐话题

相关热帖

近期热帖

历年真题 真题热练榜 24小时
技术(软件)/信息技术类
查看全部

近期精华帖

热门推荐