Skip to content

Commit c7e9ba9

Browse files
committed
[Simulation] baekjoon-2564
1 parent 6ff729b commit c7e9ba9

File tree

4 files changed

+51
-0
lines changed

4 files changed

+51
-0
lines changed

โ€ŽREADME.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
| 23 | | [Baekjoon-15683 ๊ฐ์‹œ](./src/Simulation/P15683) | |
6363
| 24 | | [SWEA-4014 ํ™œ์ฃผ๋กœ ๊ฑด์„ค](./src/Simulation/swea4014) | ์‚ผ์„ฑ SW ์—ญ๋Ÿ‰ ํ…Œ์ŠคํŠธ ๊ธฐ์ถœ |
6464
| 25 | | [Baekjoon-17779 ๊ฒŒ๋ฆฌ๋งจ๋”๋ง 2](./src/Simulation/P17779) | |
65+
| 26 | | [Baekjoon-2564 ๊ฒฝ๋น„์›](./src/Simulation/P2564) | |
6566

6667
## String
6768

โ€Žsrc/Simulation/P2564/Main.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package Simulation.P2564;
2+
3+
import java.io.*;
4+
import java.util.*;
5+
6+
public class Main {
7+
8+
static int W, H, N, sum;
9+
static int[] pos;
10+
11+
public static void main(String[] args) throws Exception {
12+
System.setIn(new FileInputStream("src/Simulation/P2564/input.txt"));
13+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
14+
StringTokenizer st = new StringTokenizer(br.readLine());
15+
16+
W = Integer.parseInt(st.nextToken());
17+
H = Integer.parseInt(st.nextToken());
18+
N = Integer.parseInt(br.readLine());
19+
20+
pos = new int[N+1];
21+
for (int i = 0; i <= N; i++) {
22+
st = new StringTokenizer(br.readLine());
23+
int d = Integer.parseInt(st.nextToken());
24+
int k = Integer.parseInt(st.nextToken());
25+
if (d == 1) pos[i] = k;
26+
else if (d == 2) pos[i] = 2*W+H-k;
27+
else if (d == 3) pos[i] = 2*(W+H)-k;
28+
else pos[i] = W+k;
29+
}
30+
31+
int x = pos[N];
32+
for (int i = 0; i < N; i++) {
33+
int dist = Math.abs(x-pos[i]);
34+
sum += Math.min(dist, 2*(W+H)-dist);
35+
}
36+
37+
System.out.println(sum);
38+
}
39+
}

โ€Žsrc/Simulation/P2564/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## [baekjoon-2564] ๊ฒฝ๋น„์›
2+
3+
![image](https://user-images.githubusercontent.com/22045163/114589793-fa307400-9cc2-11eb-886f-2d3a39ab8772.png)
4+
5+
![image](https://user-images.githubusercontent.com/22045163/114589833-03214580-9cc3-11eb-93b0-27e94d169894.png)

โ€Žsrc/Simulation/P2564/input.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
10 5
2+
3
3+
1 4
4+
3 2
5+
2 8
6+
2 3

0 commit comments

Comments
ย (0)