8.22 美团 笔试
4+1道编程题
- 没用正则表达式, 暴力法, ac。
- 很费解,不知道哪里错了,一直都是54%,,,求大佬指点。
```java
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
HashMap<Integer,Integer> map = new HashMap<Integer, Integer>();
for(int i= 1;i<=n;i++){
int v = sc.nextInt();
int w = sc.nextInt();
int price = v+w*2;
map.put(i,price);
}
PriorityQueue<Integer> queue = new PriorityQueue<Integer>((a,b)->{
if(map.get(a) != map.get(b)) return map.get(a)- map.get(b);
return b-a;
});
for(int key:map.keySet()){
queue.offer(key);
if(queue.size()>m) queue.poll();
}
StringBuilder res = new StringBuilder();
List<Integer> list = new ArrayList<Integer>();
while(!queue.isEmpty()){
list.add(queue.poll());
}
Collections.sort(list);
for(int a :list){
res.append(a+" ");
}
System.out.println(res.substring(0, res.length() - 1));
}}
- 题都没读明白, 是这个堆是怎么分呐, 是子堆的两堆,还是一共只有两堆。。。样例给我的感觉是,只有两堆,按这个做的,只a了18%。。。不知道该咋分。。求大佬们指点一下
查看14道真题和解析