思路:感觉问题不大,不知道为啥一直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>() {@Overridepublic 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;}@Overridepublic String toString() {return "("+i+","+h+")";} }
}