该题简单明了,就是要你求出(ai + aj)2 + di + dj的最小值。那么,首先我们可以使用两个数组来分别存储输入的数据,通过双循环遍历得出所有的结果,同时得出该层的最小值,将其存入minResult[]数组,最后将数组数据遍历输出即可。
import java.util.Scanner;
public class numFriends {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
int n=input.nextInt();
int[] a = new int[n];
int[] b = new int[n];
int[][] result = new int[n][n];
int[] minResult = new int[n];
for(int i = 0; i < n; i++){
a[i] = input.nextInt();
b[i] = input.nextInt();
}
for (int i = 0; i < n; i++){
int reMin = 99999;
for (int j = 0; j < n; j++){
result[i][j] = (int) Math.pow(a[i]+a[j],2) + b[i] + b[j];
if (reMin > result[i][j]){
reMin = result[i][j];
}
}
minResult[i] = reMin;
}
for (int res : minResult){
System.out.println(res);
}
}
}