(SPOJ) Álbum de Fotos - Solution
Link to the problem: http://br.spoj.com/problems/ALBUM12/
The solution below tries all the possible configurations for the photos.
import java.io.*;
import java.util.*;
class Main {
public void process() throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
String line = br.readLine();
String[] s = line.split(" ");
int albumWidth = Integer.parseInt(s[0]);
int albumLength = Integer.parseInt(s[1]);
line = br.readLine();
s = line.split(" ");
int p1Width = Integer.parseInt(s[0]);
int p1Length = Integer.parseInt(s[1]);
line = br.readLine();
s = line.split(" ");
int p2Width = Integer.parseInt(s[0]);
int p2Length = Integer.parseInt(s[1]);
if ((p1Width+p2Width <= albumWidth && Math.max(p1Length, p2Length) <= albumLength) || (p1Width+p2Width <= albumLength && Math.max(p1Length, p2Length) <= albumWidth)) {
bw.write("S\n");
}
else if ((p1Width+p2Length <= albumWidth && Math.max(p1Length, p2Width) <= albumLength) || (p1Width+p2Length <= albumLength && Math.max(p1Length, p2Width) <= albumWidth)) {
bw.write("S\n");
}
else if ((p1Length+p2Width <= albumWidth && Math.max(p1Width, p2Length) <= albumLength) || (p1Length+p2Width <= albumLength && Math.max(p1Width, p2Length) <= albumWidth)) {
bw.write("S\n");
}
else if ((p1Length+p2Length <= albumWidth && Math.max(p1Width, p2Width) <= albumLength) || (p1Length+p2Length <= albumLength && Math.max(p1Width, p2Width) <= albumWidth)) {
bw.write("S\n");
}
else {
bw.write("N\n");
}
bw.flush();
bw.close();
return;
}
public static void main(String[] args) throws NumberFormatException, IOException {
Main m = new Main();
m.process();
System.exit(0);
}
}
The solution below tries all the possible configurations for the photos.
import java.io.*;
import java.util.*;
class Main {
public void process() throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
String line = br.readLine();
String[] s = line.split(" ");
int albumWidth = Integer.parseInt(s[0]);
int albumLength = Integer.parseInt(s[1]);
line = br.readLine();
s = line.split(" ");
int p1Width = Integer.parseInt(s[0]);
int p1Length = Integer.parseInt(s[1]);
line = br.readLine();
s = line.split(" ");
int p2Width = Integer.parseInt(s[0]);
int p2Length = Integer.parseInt(s[1]);
if ((p1Width+p2Width <= albumWidth && Math.max(p1Length, p2Length) <= albumLength) || (p1Width+p2Width <= albumLength && Math.max(p1Length, p2Length) <= albumWidth)) {
bw.write("S\n");
}
else if ((p1Width+p2Length <= albumWidth && Math.max(p1Length, p2Width) <= albumLength) || (p1Width+p2Length <= albumLength && Math.max(p1Length, p2Width) <= albumWidth)) {
bw.write("S\n");
}
else if ((p1Length+p2Width <= albumWidth && Math.max(p1Width, p2Length) <= albumLength) || (p1Length+p2Width <= albumLength && Math.max(p1Width, p2Length) <= albumWidth)) {
bw.write("S\n");
}
else if ((p1Length+p2Length <= albumWidth && Math.max(p1Width, p2Width) <= albumLength) || (p1Length+p2Length <= albumLength && Math.max(p1Width, p2Width) <= albumWidth)) {
bw.write("S\n");
}
else {
bw.write("N\n");
}
bw.flush();
bw.close();
return;
}
public static void main(String[] args) throws NumberFormatException, IOException {
Main m = new Main();
m.process();
System.exit(0);
}
}
Comments
Post a Comment