思路:感觉问题不大,不知道为啥一直WA
WA代码:
package 练习;
import java.util.*;
import java.io.*;
import java.lang.*;
public class Main{
public static void main(String[] args) {
Scanner sc=new Scanner (System.in);
int n=sc.nextInt();
List<bug>bug=new ArrayList<>();
boolean b[]=new boolean [n];
Arrays.fill(b, true);
for(int i=0;i<n;i++) {
int a=sc.nextInt();
if(a==1) {
long x=sc.nextInt();
long y=sc.nextInt();
long h=sc.nextInt();//血量
bug.add(new bug(x,y,h,i));
}else {
long x=sc.nextInt();
long y=sc.nextInt();
long atk=sc.nextInt();//单次伤害
long r=sc.nextInt();//攻击半径
//操作
Collections.sort(bug,new Comparator<bug>() {
@Override
public int compare(bug o1, bug o2) {
long s1=Math.abs((long)Math.pow((o1.x-x), 2)+(long)Math.pow((o1.y-y), 2));
long s2=Math.abs((long)Math.pow((o2.x-x), 2)+(long)Math.pow((o2.y-y), 2));
if(s1>s2) {
return 1;
}else if(s1<s2) {
return -1;
}else {
if(o1.i>o2.i) {
return 1;
}else {
return -1;
}
}
}
});
long sha=atk*3;
long xx = Integer.MAX_VALUE,yy=Integer.MAX_VALUE;//记录最近的虫子且活着的
for(bug o:bug) {
if(b[o.i]) {//活着即最近
xx=o.x;
yy=o.y;
break;
}
}
if(xx==yy&&xx==Integer.MAX_VALUE)continue;
for(bug o:bug) {
if(!b[o.i])continue;//如果虫子死了
long ss=Math.abs((long)Math.pow((o.x-xx), 2)+(long)Math.pow((o.y-yy), 2));
if(ss<=r*r) {//距离问题
if(b[o.i]&&o.h<=sha) {//虫子还活着,且在攻击范围内,且生命小于攻击
b[o.i]=false;//虫子死了
}else if(o.h>sha) {//虫子在承受攻击后活着,人死
//System.out.println(o.h);
o.h-=sha;
//System.out.println(o.h);
b[i]=false;
}
}else {//剪枝
break;
}
}
}
}
System.out.println(bug);
for(boolean i:b) {
System.out.println(i?"Yes":"No");
}
}
static class bug{//虫子类
long x;
long y;
long h;
int i;//出现顺序
public bug(long x, long y, long h, int i) {
this.x = x;
this.y = y;
this.h = h;
this.i = i;
}
@Override
public String toString() {
return "("+i+","+h+")";
}
}
}