Advertisement
Josif_tepe

Untitled

May 4th, 2022
573
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.92 KB | None
  1. // Online Java Compiler
  2. // Use this editor to write, compile and run your Java code online
  3. import java.util.*;
  4. class HelloWorld {
  5.     public static void main(String[] args) {
  6.         int n = 5;
  7.         int[] x = new int[n];
  8.         int[] y = new int[n];
  9.        
  10.         Scanner sc = new Scanner(System.in);
  11.         for(int i = 0 ;i < n; i++) {
  12.             x[i] = sc.nextInt();
  13.             y[i] = sc.nextInt();
  14.         }
  15.         double najkratko = 2e9;
  16.         int A = -1, B  = -1;
  17.         for(int i = 0; i < n; i++) {
  18.             for(int j = i + 1; j < n; j++) {
  19.                 double d = Math.sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
  20.                 if(najkratko > d) {
  21.                     najkratko = d;
  22.                     A = i;
  23.                     B = j;
  24.                 }
  25.                
  26.             }
  27.         }
  28.         System.out.println(najkratko + " " + A + " " + B);
  29.     }
  30. }
Advertisement
RAW Paste Data Copied
Advertisement