Skip to content

Commit 59ad7f5

Browse files
committed
[Simulation] baekjoon-2477
1 parent 5bec0b0 commit 59ad7f5

File tree

4 files changed

+86
-0
lines changed

4 files changed

+86
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
| 14 | | [Baekjoon-3954 Brainf**k 인터프리터](./src/Simulation/P3954) | 삼성 A형 기출 |
4444
| 15 | | [Baekjoon-10163 색종이](./src/Simulation/P10163) | |
4545
| 16 | | [Baekjoon-13300 방 배정](./src/Simulation/P13300) | |
46+
| 17 | | [Baekjoon-2477 참외밭](./src/Simulation/P2477) | |
4647

4748
## String
4849

src/Simulation/P2477/Main.java

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package Simulation.P2477;
2+
3+
import java.io.BufferedReader;
4+
import java.io.FileInputStream;
5+
import java.io.InputStreamReader;
6+
import java.util.StringTokenizer;
7+
8+
public class Main {
9+
10+
static int K, D, L, W, H, w, h, sub = 1;
11+
static int[] edges = new int[6];
12+
13+
public static void main(String[] args) throws Exception {
14+
System.setIn(new FileInputStream("src/Simulation/P2477/input.txt"));
15+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
16+
StringTokenizer st;
17+
18+
K = Integer.parseInt(br.readLine());
19+
for (int i = 0; i < 6; i++) {
20+
st = new StringTokenizer(br.readLine());
21+
D = Integer.parseInt(st.nextToken());
22+
L = Integer.parseInt(st.nextToken());
23+
24+
if (D <= 2 && W < L) { W = L; w = i; }
25+
else if (D >= 3 && H < L) { H = L; h = i; }
26+
edges[i] = L;
27+
}
28+
29+
edges[w] = edges[h] = 0;
30+
edges[getIdx(w-1)] = edges[getIdx(w+1)] = 0;
31+
edges[getIdx(h-1)] = edges[getIdx(h+1)] = 0;
32+
33+
for (int i = 0; i < 6; i++) {
34+
if (edges[i] != 0) sub *= edges[i];
35+
}
36+
37+
System.out.println((W*H - sub) * K);
38+
}
39+
40+
static int getIdx(int i) {
41+
if (i < 0) return i+6;
42+
if (i >= 6) return i-6;
43+
return i;
44+
}
45+
}

src/Simulation/P2477/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## [baekjoon-2477] 참외밭
2+
3+
![image](https://user-images.githubusercontent.com/22045163/109010761-88d93980-76f3-11eb-9a0f-8d925c84077c.png)
4+
5+
![image](https://user-images.githubusercontent.com/22045163/109010800-94c4fb80-76f3-11eb-9bca-7f70644aa6ee.png)

src/Simulation/P2477/input.txt

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
7
2+
1 160
3+
3 50
4+
2 100
5+
4 20
6+
2 60
7+
4 30
8+
9+
3 160
10+
1 30
11+
4 60
12+
1 20
13+
4 100
14+
2 50
15+
16+
3 20
17+
1 100
18+
4 50
19+
2 160
20+
3 30
21+
1 60
22+
23+
3 30
24+
1 60
25+
3 20
26+
1 100
27+
4 50
28+
2 160
29+
30+
1 160
31+
3 50
32+
2 100
33+
4 20
34+
2 60
35+
4 30

0 commit comments

Comments
 (0)