弹幕

弹幕

import java.util.*;

public class Solution {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.nextLine());
        List<List<Integer>> list = new ArrayList<>();
        int big = 0;
        for (int i = 0;i<N;i++){
            String temp = sc.nextLine();
            String[] tempString = temp.split(" ");
            int first = Integer.parseInt(tempString[0]);
            int second = Integer.parseInt(tempString[1]);
            List<Integer> tempList = new ArrayList<>();
            tempList.add(first);
            tempList.add(second);
            if (second>big)big=second;
            list.add(tempList);
        }
        Map<Integer,Integer> map = new HashMap<>();
        for (List<Integer> tempList:list){
            int first = tempList.get(0);
            int second = tempList.get(1);
            for (int i = first;i<second;i++){
                if(map.containsKey(i)){
                    map.put(i,map.get(i)+1);
                }else {
                    map.put(i,1);
                }
            }
        }
        int max = 0;
        for(int val:map.values()){
            if (val>max)max=val;
        }
        int maxKey = 0;
        int minKey = 100;
        for (int val:map.keySet()){
            if (val>maxKey)maxKey=val;
            if (val<minKey)minKey=val;
        }
        for (int i=minKey;i<=maxKey;i++){
            if (map.get(i)==max){
                System.out.println(i+" "+(i+1));
            }
        }

    }

}

弹幕

原文地址:https://www.cnblogs.com/LoganChen/p/13721412.html