Rezultati

Up. imeNalogaJezikRezultatČas oddaje
ekipa5-2017 Črte Java 0/100Prekoračen čas (TLE) 20. apr '17 @ 17:20

Test Točke Porabljen spomin Porabljen čas Status
#1 10/10 50,914 MiB 0,000 s OK
#2 10/10 63,484 MiB 0,347 s OK
#3 10/10 62,465 MiB 0,324 s OK
#4 10/10 448,410 MiB 4,369 s OK
#5 0/10 462,582 MiB 10,853 s Prekoračen čas
#6 0/10 431,125 MiB 10,766 s Prekoračen čas
#7 0/10 362,574 MiB 10,727 s Prekoračen čas
#8 0/10 424,000 MiB 10,826 s Prekoračen čas
#9 0/10 331,063 MiB 10,892 s Prekoračen čas
#10 0/10 336,113 MiB 10,761 s Prekoračen čas

Ocenjevani program (Main.java):
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int stVhodov = scanner.nextInt();
        scanner.nextLine();

        LinkedList<String> points = new LinkedList<>();
        for(int pointCount = 0; pointCount < stVhodov; pointCount++){
            points.add(scanner.nextLine().trim());
        }

        HashMap<Double, Integer> razdaljeCount = new HashMap<>();

        for(int i = 0; i < points.size(); i++)
            for(int j =i+1; j < points.size(); j++){
                Double distance = getDistance(points.get(i), points.get(j));

                if(!razdaljeCount.containsKey(distance)){
                    razdaljeCount.put(distance, 0);
                }

                razdaljeCount.put(distance, razdaljeCount.get(distance)+1);
            }


        int pairCount = 0;
        for(Double distance:razdaljeCount.keySet()){
            //System.out.println("distance:" + distance + " occ: " + razdaljeCount.get(distance));
            if(razdaljeCount.get(distance) > 1){
                pairCount += binomial(razdaljeCount.get(distance));
            }
        }

        System.out.println(pairCount);


    }

    private static Integer binomial(int n) {
        return n*(n-1)/2;
    }

    private static Double getDistance(String s1, String s2) {
        double x1,y1;
        double x2,y2;
        x1 = Double.parseDouble(s1.split(" ")[0]);
        y1 = Double.parseDouble(s1.split(" ")[1]);
        x2 = Double.parseDouble(s2.split(" ")[0]);
        y2 = Double.parseDouble(s2.split(" ")[1]);

        double xDelta = x1 - x2;
        double yDelta = y1 - y2;
        return Math.sqrt((xDelta* xDelta) + (yDelta*yDelta));
    }

}