广联达0916笔试
做完出来,刷牛客,发现3道编程都是广联达之前笔试的原题。。。
第一道长草ac
第二道元素91%,超时
第三道范围攻击81%,有错误,想知道第三道哪里没考虑到,求指点
import java.util.Scanner;
import java.util.TreeMap;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int y = sc.nextInt();
TreeMap<Integer,Integer> map = new TreeMap<>();
for (int i = 0; i < n; i++) {
int x = sc.nextInt();
int hp = sc.nextInt();
map.put(x,hp);
}
int count = 0;
for (int item:map.keySet()) {
int x =map.get(item);
if (x>0){
for (int other:map.keySet()) {
if (other<=item+2*y){
map.put(other,map.get(other)-x);
}
}
count+=x;
}
}
System.out.println(count);
}
}
查看15道真题和解析