(SPOJ) 3827 - Pontos - Solução
import java.io.*;
import java.util.*;
import java.text.DecimalFormat;
import java.lang.Math;
class Main {
public static void main(String[] args) throws NumberFormatException, IOException {
Main processando = new Main();
processando.processa();
System.exit(0);
}
void processa() throws NumberFormatException, IOException {
String line = "";
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
line = br.readLine();
StringTokenizer tokenizer = new StringTokenizer(line);
int pontos = Integer.parseInt(tokenizer.nextToken());
int[][] coord = new int[pontos][2];
for (int i = 0; i < pontos; i++) {
line = br.readLine();
tokenizer = new StringTokenizer(line);
for (int j = 0; j < 2; j++) {
coord[i][j] = Integer.parseInt(tokenizer.nextToken());
}
}
if (pontos <= 1) {
System.out.println("0.000");
return;
}
long x;
long y;
long diagonal;
long menorArea = 0x3f3f3f3f3f3f3f3fl;
for (int i = 0; i < pontos; i++) {
for (int j = i+1; j < pontos; j++) {
x = Math.abs(coord[j][0]-coord[i][0]);
y = Math.abs(coord[j][1]-coord[i][1]);
diagonal = (x*x)+(y*y);
if (diagonal < menorArea) {
menorArea = diagonal;
}
}
}
// Sempre usar esse Locale para imprimir
System.out.println(String.format(new Locale("en", "US"), "%.3f", Math.sqrt(menorArea)));
return;
}
}
import java.util.*;
import java.text.DecimalFormat;
import java.lang.Math;
class Main {
public static void main(String[] args) throws NumberFormatException, IOException {
Main processando = new Main();
processando.processa();
System.exit(0);
}
void processa() throws NumberFormatException, IOException {
String line = "";
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
line = br.readLine();
StringTokenizer tokenizer = new StringTokenizer(line);
int pontos = Integer.parseInt(tokenizer.nextToken());
int[][] coord = new int[pontos][2];
for (int i = 0; i < pontos; i++) {
line = br.readLine();
tokenizer = new StringTokenizer(line);
for (int j = 0; j < 2; j++) {
coord[i][j] = Integer.parseInt(tokenizer.nextToken());
}
}
if (pontos <= 1) {
System.out.println("0.000");
return;
}
long x;
long y;
long diagonal;
long menorArea = 0x3f3f3f3f3f3f3f3fl;
for (int i = 0; i < pontos; i++) {
for (int j = i+1; j < pontos; j++) {
x = Math.abs(coord[j][0]-coord[i][0]);
y = Math.abs(coord[j][1]-coord[i][1]);
diagonal = (x*x)+(y*y);
if (diagonal < menorArea) {
menorArea = diagonal;
}
}
}
// Sempre usar esse Locale para imprimir
System.out.println(String.format(new Locale("en", "US"), "%.3f", Math.sqrt(menorArea)));
return;
}
}
Comments
Post a Comment