兰博教训提莫之后,然后和提莫讨论起约德尔人,谈起约德尔人,自然少不了一个人,那 就是黑默丁格------约德尔人历史上最伟大的科学家. 提莫说,黑默丁格最近在思考一个问题:黑默丁格有三个炮台,炮台能攻击到距离它小于等于R的敌人 (两点之间的距离为两点之间的直线距离,例如(3,0),(0,4)之间的距离是5),如果一个炮台能攻击 到敌人,那么就会对敌人造成1×的伤害.黑默丁格将三个炮台放在N*M方格中的点上,并且给出敌人 的坐标. 问:那么敌人受到伤害会是多大?
每一行输入9个整数R x1 y1 x2 y2 x3 y3 x0 y0 其中R代表炮台攻击的最大距离,(x1,y1),(x2,y2),(x3,y3)代表三个炮台的坐标,(x0,y0)代表敌人的坐标。
输出一行,这一行代表敌人承受的最大伤害,(如果每个炮台都不能攻击到敌人,输出0×)
1 1 1 2 2 3 3 1 2
2x
public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNext()) { int R = scanner.nextInt(); int x1 = scanner.nextInt(); int y1 = scanner.nextInt(); int x2 = scanner.nextInt(); int y2 = scanner.nextInt(); int x3 = scanner.nextInt(); int y3 = scanner.nextInt(); int x0 = scanner.nextInt(); int y0 = scanner.nextInt(); int count = 0; if (Math.sqrt((x1 - x0)*(x1 - x0) + (y1 - y0)*(y1 - y0)) < R) { count++; } if (Math.sqrt((x2 - x0)*(x2 - x0) + (y2 - y0)*(y2 - y0)) < R) { count++; } if (Math.sqrt((x3 - x0)*(x3 - x0) + (y3 - y0)*(y3 - y0)) < R) { count++; } System.out.println(count + "x"); } } }
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String line; while((line = br.readLine()) != null){ String[] params = line.split(" "); int R = Integer.parseInt(params[0]); int x1 = Integer.parseInt(params[1]); int y1 = Integer.parseInt(params[2]); int x2 = Integer.parseInt(params[3]); int y2 = Integer.parseInt(params[4]); int x3 = Integer.parseInt(params[5]); int y3 = Integer.parseInt(params[6]); int x0 = Integer.parseInt(params[7]); int y0 = Integer.parseInt(params[8]); int count = 0; if((x1 - x0)*(x1 - x0) + (y1 - y0)*(y1 - y0) <= R*R){ count++; } if((x2 - x0)*(x2 - x0) + (y2 - y0)*(y2 - y0) <= R*R){ count++; } if((x3 - x0)*(x3 - x0) + (y3 - y0)*(y3 - y0) <= R*R){ count++; } System.out.println(count + "x"); } } }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while(sc.hasNext()){ int R = sc.nextInt(); Point[] nums = new Point[4]; int i = -1; while(i++ < 3 && sc.hasNext()){ int x = sc.nextInt(); int y = sc.nextInt(); nums[i] = new Point(x , y); } int farm = 0; for (int j = 0; j < 3; j++) { if(nums[3].distance(nums[j]) <= R) farm++; } System.out.println(farm + "x"); } } static class Point{ private int x; private int y; public Point(int x, int y) { this.x = x; this.y = y; } public double distance(Point point){ double distance = (x - point.x) * (x - point.x) + (y - point.y) * (y - point.y); return Math.pow(distance , 0.5); } } }
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[] tab1 = new int[2]; int[] tab2 = new int[2]; int[] tab3 = new int[2]; int[] tab = new int[2]; tab1[0] = sc.nextInt(); tab1[1] = sc.nextInt(); tab2[0] = sc.nextInt(); tab2[1] = sc.nextInt(); tab3[0] = sc.nextInt(); tab3[1] = sc.nextInt(); tab[0] = sc.nextInt(); tab[1] = sc.nextInt(); int res = 0; res += solve(R, tab1, tab); res += solve(R, tab2, tab); res += solve(R, tab3, tab); System.out.println(res + "x"); } } private static int solve(int R, int[] tab1, int[] tab){ double dis = Math.sqrt(Math.pow(tab1[0]-tab[0],2) + Math.pow(tab1[1]-tab[1],2)); return dis > R ? 0 : 1; } }
import java.util.Scanner; public class Main { private static class Point{ private int x; private int y; public Point(int x, int y) { // TODO Auto-generated constructor stub this.x = x; this.y = y; } public double getDistance(Point point){ int dd = (x - point.x) * (x - point.x) + (y - point.y) * (y - point.y); return Math.pow(dd, 0.5); } } public static void main(String[] args) { Scanner in = new Scanner(System.in); while (in.hasNext()) { int r = in.nextInt(); Point[] b = new Point[4]; int i = -1; while (++i<4 && in.hasNext()) { int x = in.nextInt(); int y = in.nextInt(); b[i] = new Point(x, y); } int harm = 0; for(int j=0; j<3; j++){ if (b[3].getDistance(b[j])<=r) { harm++; } } System.out.println(harm+"x"); } } }
//到三个炮台分别到敌人的距离即可 import java.util.*; public class Main { public static void main(String[] args){ Scanner sc = new Scanner(System.in); while(sc.hasNext()){ String[] s= sc.nextLine().split(" "); int R = Integer.parseInt(s[0]); int[] x = new int[3]; int[] y = new int[3]; x[0] = Integer.parseInt(s[1]); y[0] = Integer.parseInt(s[2]); x[1] = Integer.parseInt(s[3]); y[1] = Integer.parseInt(s[4]); x[2] = Integer.parseInt(s[5]); y[2] = Integer.parseInt(s[6]); int x0 = Integer.parseInt(s[7]); int y0 = Integer.parseInt(s[8]); int count= 0; for(int i=0;i<3;i++){//循环3次,分别算三个距离 if(Math.sqrt(Math.pow(x[i]-x0,2) + Math.pow(y[i]-y0,2)) <= R){ count++; } } System.out.println(count+"x"); } } }