QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#533050#8068. Building RoadstheodoregossettWA 61ms39108kbJava81.4kb2024-08-25 16:21:262024-08-25 16:21:26

Judging History

你现在查看的是最新测评结果

  • [2024-08-25 16:21:26]
  • 评测
  • 测评结果:WA
  • 用时:61ms
  • 内存:39108kb
  • [2024-08-25 16:21:26]
  • 提交

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'