Skip to content

Commit db37669

Browse files
committed
[Week10] BOJ_20055: 컨베이어 벨트 위의 로봇
1 parent 13623ac commit db37669

File tree

2 files changed

+110
-0
lines changed

2 files changed

+110
-0
lines changed

weekly/week10/BOJ_12919_A와B2/sukangpunch.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,4 @@ private static void checkChange(String t) {
4141
}
4242
}
4343
}
44+
1
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
package study.week10;
2+
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
import java.io.InputStreamReader;
6+
import java.util.LinkedList;
7+
import java.util.List;
8+
9+
// 컨베이어 벨트 위의 로봇
10+
// 구현
11+
12+
/**
13+
* 시간복잡도 : O()
14+
* 그냥 빡 구현 문제이다.
15+
* 컨베이어 벨트의 칸에 해당하는 값을 List에 저장한다.
16+
* 1. 컨베이어 벨트를 회전시킨다.(리스트의 마지막 컨베이어 벨트를 가장 처음으로 이동)
17+
* 1.1 이 때, N 위치에 로봇이 있다면 로봇을 내린다(robot 필드를 false 로 수정)
18+
* 2. 로봇을 이동 시킨다, 먼저 올라온 로봇부터 처리하기위해 N-1부터 1까지 탐색
19+
* 2.1 만약 로봇으 이동시켰는데 N 위치에 로봇이 오게 된다면 바로 내린다.(robot 필드 fasle)
20+
* 3. 1번 위치에 로봇을 올린다(만약 로봇이 있거나 내구도가 0이라면 안올림)
21+
* 위 연산을 반복하면 된다. cnt 비교 연산을 cnt >= k 로 두었는데, 어짜피 내구도가 0인 블락이 k개 일때의 "레벨" 만 알면 되기 때문이다.
22+
*/
23+
public class BOJ_20055 {
24+
25+
static class Block {
26+
27+
int durability;
28+
int num;
29+
boolean robot;
30+
31+
public Block(int durability, int num) {
32+
this.durability = durability;
33+
this.num = num;
34+
this.robot = false;
35+
}
36+
}
37+
38+
static int N;
39+
static int K;
40+
static List<Block> blocks;
41+
static int level;
42+
43+
public static void main(String[] args) throws IOException {
44+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
45+
46+
String[] s = br.readLine().split(" ");
47+
48+
N = Integer.parseInt(s[0]);
49+
K = Integer.parseInt(s[1]);
50+
51+
blocks = new LinkedList<>();
52+
s = br.readLine().split(" ");
53+
54+
for (int i = 1; i <= 2 * N; i++) {
55+
int durability = Integer.parseInt(s[i - 1]);
56+
blocks.add(new Block(durability, i));
57+
}
58+
59+
simulate();
60+
61+
System.out.println(level);
62+
}
63+
64+
private static void simulate() {
65+
level = 1;
66+
int cnt = 0;
67+
while(true){
68+
// 1. 회전하기
69+
blocks.add(0, blocks.remove(2*N-1));
70+
if(blocks.get(N-1).robot){
71+
blocks.get(N-1).robot = false;
72+
}
73+
74+
// 2. 올라가 있는 로봇 이동시키기
75+
for(int i=N-1; i>0; i--){
76+
if(blocks.get(i-1).robot && !blocks.get(i).robot && blocks.get(i).durability > 0){
77+
blocks.get(i-1).robot = false;
78+
blocks.get(i).robot = true;
79+
blocks.get(i).durability -= 1;
80+
81+
if(blocks.get(i).durability == 0){
82+
cnt++;
83+
}
84+
85+
if(i==N-1){
86+
blocks.get(i).robot = false;
87+
}
88+
}
89+
}
90+
91+
// 3. 1번에 로봇 올리기
92+
Block block = blocks.get(0);
93+
if(!block.robot && block.durability > 0){
94+
block.robot = true;
95+
block.durability -= 1;
96+
97+
if(block.durability == 0){
98+
cnt++;
99+
}
100+
}
101+
102+
if(cnt >= K){
103+
return;
104+
}
105+
106+
level += 1;
107+
}
108+
}
109+
}

0 commit comments

Comments
 (0)