第一题
package ccf202206; import java.util.Scanner; public class p1 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); double[] num = new double[n]; double sum = 0; for (int i = 0; i < n; i++) { num[i] = sc.nextDouble(); sum += num[i]; } double x = sum / n; sum = 0; for (int i = 0; i < n; i++) { sum += (num[i] - x) * (num[i] - x); } double d = sum / n; for (int i = 0; i < n; i++) { System.out.println((num[i] - x) / (Math.sqrt(d))); } } }
第二题
package ccf202206; 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]); long L = Integer.parseInt(temp[1]); int S = Integer.parseInt(temp[2]); long[] x = new long[n]; long[] y = new long[n]; long[][] B = new long[S + 1][S + 1]; for (int i = 0; i < n; i++) { temp = bf.readLine().split(" "); x[i] = Integer.parseInt(temp[0]); y[i] = Integer.parseInt(temp[1]); } int sum = 0; for (int i = S; i >= 0; i--) { temp = bf.readLine().split(" "); for (int j = 0; j <= S; j++) { B[i][j] = Integer.parseInt(temp[j]); if (B[i][j] == 1) { sum++; } } } int count = 0; for (int i = 0; i < n; i++) { if (x[i] + S > L || y[i] + S > L) { continue; } boolean flag = true; long[][] newB = new long[S + 1][S + 1]; long x0 = x[i]; long y0 = y[i]; int t = 0;//t是当x0,y0为小地图原点时,小地图内树的数量 for (int p = 0; p < n; p++) { if ((x[p] - x0) >= 0 && (y[p] - y0) >= 0 && (x[p] - x0) <= S && (y[p] - y0) <= S) { t++; newB[(int) (x[p] - x0)][(int) (y[p] - y0)] = 1; } } if (t == sum) { for (int j = 0; j <= S; j++) { for (int k = 0; k <= S; k++) { if (newB[j][k] != B[j][k]) { flag = false; break; } } } } else { flag = false; } if (flag) { count++; } } System.out.println(count); } }