大根堆的使用
大根堆的定义是这样的
PriorityQueue<int[]> pq = new PriorityQueue<int[]>(
new Comparator<int[]>() {
public int compare(int[] cp1, int[] cp2) {
return cp1[0] == cp2[0] ? cp2[1] - cp1[1] : cp2[0] - cp1[0];
}
});
这里先是判定数组角标0的位置是否相同,如果不相同就按照数组角标0的数据降序排序,否则按照数组角标1的数据降序排序。
如果不是数组,而是单独的Integer,那么大根堆的定义是这样的
PriorityQueue<Integer> pq = new PriorityQueue<>(new Comparator<Integer>