(SPOJ) Caçadores de Mitos - Solution
Link to the problem: http://br.spoj.com/problems/MITO09/
For this problem, we only need to check if a position in the matrix is mentioned more than one time.
import java.io.*;
import java.util.*;
class Main {
public void process() throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String line = br.readLine();
int numRegisters = Integer.parseInt(line);
boolean notTrue = false;
int[][] matrix = new int[501][501];
for (int i = 0; i < numRegisters; i++) {
line = br.readLine();
String[] s = line.split(" ");
int row = Integer.parseInt(s[0]);
int col = Integer.parseInt(s[1]);
if (matrix[row][col] == 1) {
notTrue = true;
break;
}
matrix[row][col] = 1;
}
br.close();
if (notTrue) {
System.out.println("1");
}
else {
System.out.println("0");
}
return;
}
public static void main(String[] args) throws NumberFormatException, IOException {
Main m = new Main();
m.process();
System.exit(0);
}
}
For this problem, we only need to check if a position in the matrix is mentioned more than one time.
import java.io.*;
import java.util.*;
class Main {
public void process() throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String line = br.readLine();
int numRegisters = Integer.parseInt(line);
boolean notTrue = false;
int[][] matrix = new int[501][501];
for (int i = 0; i < numRegisters; i++) {
line = br.readLine();
String[] s = line.split(" ");
int row = Integer.parseInt(s[0]);
int col = Integer.parseInt(s[1]);
if (matrix[row][col] == 1) {
notTrue = true;
break;
}
matrix[row][col] = 1;
}
br.close();
if (notTrue) {
System.out.println("1");
}
else {
System.out.println("0");
}
return;
}
public static void main(String[] args) throws NumberFormatException, IOException {
Main m = new Main();
m.process();
System.exit(0);
}
}
Comments
Post a Comment