(SPOJ) 814 - Macaco-prego - Solução
import java.io.*;
import java.util.*;
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));
int contador = 0;
while ((line = br.readLine()) != null) {
StringTokenizer tokenizer = new StringTokenizer(line);
int numLinhas = Integer.valueOf(tokenizer.nextToken());
if (numLinhas == 0) {
return;
}
contador++;
System.out.println("Teste " + contador);
int[] coord1 = new int[4];
int[] coord2 = new int[4];
boolean nenhum = false;
line = br.readLine();
tokenizer = new StringTokenizer(line);
for (int i = 0; i < 4; i++) {
coord1[i] = Integer.valueOf(tokenizer.nextToken());
}
for (int j = 1; j < numLinhas; j++) {
line = br.readLine();
tokenizer = new StringTokenizer(line);
for (int i = 0; i < 4; i++) {
coord2[i] = Integer.valueOf(tokenizer.nextToken());
}
coord1[0] = Math.max(coord1[0], coord2[0]);
coord1[2] = Math.min(coord1[2], coord2[2]);
coord1[1] = Math.min(coord1[1], coord2[1]);
coord1[3] = Math.max(coord1[3], coord2[3]);
if (coord1[2] <= coord1[0] || coord1[3] >= coord1[1]) {
nenhum = true;
}
}
if (nenhum == true) {
System.out.println("nenhum");
}
else {
System.out.println(coord1[0] + " " + coord1[1] + " " + coord1[2] + " " + coord1[3]);
}
System.out.println();
}
return;
}
}
import java.util.*;
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));
int contador = 0;
while ((line = br.readLine()) != null) {
StringTokenizer tokenizer = new StringTokenizer(line);
int numLinhas = Integer.valueOf(tokenizer.nextToken());
if (numLinhas == 0) {
return;
}
contador++;
System.out.println("Teste " + contador);
int[] coord1 = new int[4];
int[] coord2 = new int[4];
boolean nenhum = false;
line = br.readLine();
tokenizer = new StringTokenizer(line);
for (int i = 0; i < 4; i++) {
coord1[i] = Integer.valueOf(tokenizer.nextToken());
}
for (int j = 1; j < numLinhas; j++) {
line = br.readLine();
tokenizer = new StringTokenizer(line);
for (int i = 0; i < 4; i++) {
coord2[i] = Integer.valueOf(tokenizer.nextToken());
}
coord1[0] = Math.max(coord1[0], coord2[0]);
coord1[2] = Math.min(coord1[2], coord2[2]);
coord1[1] = Math.min(coord1[1], coord2[1]);
coord1[3] = Math.max(coord1[3], coord2[3]);
if (coord1[2] <= coord1[0] || coord1[3] >= coord1[1]) {
nenhum = true;
}
}
if (nenhum == true) {
System.out.println("nenhum");
}
else {
System.out.println(coord1[0] + " " + coord1[1] + " " + coord1[2] + " " + coord1[3]);
}
System.out.println();
}
return;
}
}
Comments
Post a Comment