Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package pontosrandom;
- import java.io.IOException;
- import java.util.*;
- /**
- *
- * @author j_mig_000
- */
- public class PontosRandom {
- /**
- * @param args the command line arguments
- */
- static String readLn(int maxLg) { //utility function to read from stdin
- byte lin[] = new byte[maxLg];
- int lg = 0, car = -1;
- String line = "";
- try {
- while (lg < maxLg) {
- car = System.in.read();
- if ((car < 0) || (car == '\n')) {
- break;
- }
- lin[lg++] += car;
- }
- } catch (IOException e) {
- return (null);
- }
- if ((car < 0) && (lg == 0)) {
- return (null); // eof
- }
- return (new String(lin, 0, lg));
- }
- static void distancia(int[] array){
- int x1,y1,x2,y2;
- float temp,distancia = Integer.MAX_VALUE;
- for(int i = 0;i<array.length - 1; i += 2 ){
- x1 = array[i];
- y1 = array[i+1];
- for (int j = 0; j < array.length - 1; j += 2) {
- x2 = array[j];
- y2 = array[j+1];
- temp = (float) Math.sqrt((Math.pow(x2-x1,2) + Math.pow(y2 - y1,2)));
- if( j!= i && temp <= distancia){
- distancia = temp;
- }
- }
- }
- System.out.printf("%.3f \n", distancia);
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- // TODO code application logic here
- int contador = 0;
- String linha;
- String tamanho = readLn(200);
- String[] numeros;
- int[] array = new int[Integer.parseInt(tamanho) * 2];
- while (contador < (Integer.parseInt(tamanho))*2) {
- linha = readLn(500);
- numeros = linha.split(" ");
- for(int i=0;i<numeros.length;i++){
- array[contador] = Integer.parseInt(numeros[i]);
- contador ++;
- }
- }
- distancia(array);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement