第一题
package ccf202009; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class p1 { public static void main(String[] args) throws IOException { BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); String[] temp = bf.readLine().split(" "); int n = Integer.parseInt(temp[0]); int X = Integer.parseInt(temp[1]); int Y = Integer.parseInt(temp[2]); int[] x = new int[n + 1]; int[] y = new int[n + 1]; double[][] list = new double[n + 1][2]; for (int i = 1; i <= n; i++) { temp = bf.readLine().split(" "); x[i] = Integer.parseInt(temp[0]); y[i] = Integer.parseInt(temp[1]); double res = Math.sqrt((X - x[i]) * (X - x[i]) + (Y - y[i]) * (Y - y[i])); list[i][0] = i; list[i][1] = res; } getSort(list, n); String res = "%.0f %n"; for (int i = 1; i < 4; i++) { System.out.printf(res, list[i][0]); } } public static void getSort(double[][] list, int n) { for (int i = 1; i <= n; i++) { for (int j = 1; j <= n - i; j++) { if (list[j][1] > list[j + 1][1]) { double d0 = list[j][0]; list[j][0] = list[j + 1][0]; list[j + 1][0] = d0; double d1 = list[j][1]; list[j][1] = list[j + 1][1]; list[j + 1][1] = d1; } } } } }
第二题
package ccf202009; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class p2 { public static void main(String[] args) throws IOException { BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); String[] temp = bf.readLine().split(" "); int n = Integer.parseInt(temp[0]); int k = Integer.parseInt(temp[1]); int t = Integer.parseInt(temp[2]); int xl = Integer.parseInt(temp[3]); int yd = Integer.parseInt(temp[4]); int xr = Integer.parseInt(temp[5]); int yu = Integer.parseInt(temp[6]); long[][] xy = new long[n][2 * t]; for (int i = 0; i < n; i++) { temp = bf.readLine().split(" "); for (int j = 0; j < 2 * t; j += 2) { xy[i][j] = Integer.parseInt(temp[j]); xy[i][j + 1] = Integer.parseInt(temp[j + 1]); } } int arrive = 0; int stop = 0; for (int i = 0; i < n; i++) { int count = 0; int flag = 0; for (int j = 0; j < 2 * t; j += 2) { long x = xy[i][j]; long y = xy[i][j + 1]; if ((x >= xl && x <= xr) && (y >= yd && y <= yu)) { count++; if (j > 0) { if ((xy[i][j - 2] >= xl && xy[i][j - 2] <= xr) && (xy[i][j - 1] >= yd && xy[i][j - 1] <= yu)) { flag++; } else { flag = 0; } if (flag >= k - 1) { stop++; break; } } } } if (count > 0) { arrive++; } } System.out.println(arrive); System.out.println(stop); } }