QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#533050 | #8068. Building Roads | theodoregossett | WA | 61ms | 39108kb | Java8 | 1.4kb | 2024-08-25 16:21:26 | 2024-08-25 16:21:26 |
Judging History
answer
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// Create scanner object for input
Scanner scanner = new Scanner(System.in);
// Read the number of locations
int n = scanner.nextInt();
// Initialize arrays to store the x and y coordinates
int[] xCoordinates = new int[n];
int[] yCoordinates = new int[n];
// Loop to read and store the coordinates
for (int i = 0; i < n; i++) {
// Read the input for each location
xCoordinates[i] = scanner.nextInt();
yCoordinates[i] = scanner.nextInt();
}
// Variable to store the minimum sum of distances
double min = 100000000;
// Outer loop to calculate the sum of distances for each location
for (int i = 0; i < n; i++) {
double temp = 0;
for (int j = 0; j < n; j++) {
int xDist = Math.abs(xCoordinates[i] - xCoordinates[j]);
int yDist = Math.abs(yCoordinates[i] - yCoordinates[j]);
temp += Math.sqrt((double) (xDist * xDist) + (double) (yDist * yDist));
}
min = Math.min(temp, min);
}
// Print the minimum sum of distances
System.out.println(min);
// Close the scanner
scanner.close();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 61ms
memory: 38400kb
input:
3 0 0 10 0 0 10
output:
20.0
result:
ok found '20.00000', expected '20.00000', error '0.00000'
Test #2:
score: -100
Wrong Answer
time: 35ms
memory: 39108kb
input:
9 0 0 10 0 0 10 -10 0 0 -10 10 10 10 -10 -10 10 -10 -10
output:
96.5685424949238
result:
wrong answer 1st numbers differ - expected: '28.28427', found: '96.56854', error = '2.41421'