炮台攻击-计算距离判断即可
炮台攻击
http://www.nowcoder.com/questionTerminal/f821a39207cd43518ccddb27fee0481d
想吐槽一下:看了一下讨论,16年的题目,以前的题目都这么容易的吗。。。。
import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); while(sc.hasNext()){ int r=sc.nextInt(); int x1=sc.nextInt(); int y1=sc.nextInt(); int x2=sc.nextInt(); int y2=sc.nextInt(); int x3=sc.nextInt(); int y3=sc.nextInt(); int x0=sc.nextInt(); int y0=sc.nextInt(); double d1=Math.sqrt((x1-x0)*(x1-x0)+(y1-y0)*(y1-y0)); double d2=Math.sqrt((x2-x0)*(x2-x0)+(y2-y0)*(y2-y0)); double d3=Math.sqrt((x3-x0)*(x3-x0)+(y3-y0)*(y3-y0)); double d=r*1.0; int cnt=0; if(d1<=d) cnt++; if(d2<=d) cnt++; if(d3<=d) cnt++; System.out.println(cnt+"x"); } } }