8000 Update 13335.cpp · hyperminji/basic-algo-lecture@bfacb59 · GitHub
[go: up one dir, main page]

Skip to content
Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit bfacb59

Browse files
authored
Update 13335.cpp
1 parent 2aa145e commit bfacb59

File tree

1 file changed

+53
-4
lines changed

1 file changed

+53
-4
lines changed

0x0D/solutions/13335.cpp

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,60 @@
1-
// Authored by : BaaaaaaaaaaarkingDog
1+
// Authored by : OceanShape
22
// Co-authored by : -
3-
// http://boj.kr/****************
3+
// http://boj.kr/d51c2bc3daaa422a9e30463512174f9b
44
#include <bits/stdc++.h>
55
using namespace std;
66

7+
int n, w, L, ans;
8+
int bridge[1001]; // 다리의 칸별 무게(트럭의 무게)를 저장하는 변수
9+
queue<int> truck; // 이동하는 트럭의 목록을 순차적으로 저장하는 변수
10+
11+
// 다리가 비었는지 확인하는 함수
12+
bool isEmpty(){
13+
for(int i = 0; i<w; ++i)
14+
if(bridge[i]) return false;
15+
return true;
16+
}
17+
18+
// 트럭의 이동을 진행하는 함수
19+
void go(){
20+
// 기존 트럭의 정보를 보존 후 덮의 씌움
21+
int tmp[1001];
22+
for(int i = 0; i<w-1; ++i)
23+
tmp[i+1]=bridge[i];
24+
for(int i = 0; i<w; ++i)
25+
bridge[i]=tmp[i];
26+
}
27+
28+
// 다리 위 트럭의 무게를 계산하는 함수
29+
int calculate(){
30+
int sum = 0;
31+
for(int i = 0; i<w; ++i)
32+
sum+=bridge[i];
33+
return sum;
34+
}
35+
736
int main(void){
837
ios::sync_with_stdio(0);
938
cin.tie(0);
10-
11-
}
39+
cin >> n >> w >> L;
40+
while(n--) {
41+
int i;
42+
cin >> i;
43+
truck.push(i); // 출발할 트럭의 목록을 순차적으로 저장
44+
}
45+
46+
do{
47+
int tmp = calculate(); // 현재 다리 위 트럭들의 무게
48+
if(tmp<=L) {
49+
tmp-=bridge[w-1]; // 나갈 트럭의 무게를 제외
50+
go();
51+
// 추가로 이동할 트럭이 있고, 다리가 무게를 버틸 경우
52+
if(!truck.empty()&&(tmp+truck.front()<=L)){
53+
bridge[0]=truck.front(); truck.pop();
54+
} else bridge[0]=0;
55+
}
56+
++ans;
57+
}while(!isEmpty()); // 모든 트럭이 이동하여 다리가 빌 때까지 반복
58+
59+
cout << ans;
60+
}

0 commit comments

Comments
 (0)
0