문제 : https://www.acmicpc.net/problem/13335
[알고리즘풀이]
단순 구현 문제로, 시간 초마다 대기 중인 차를 다리 위로 보낼 수 있으면 올리고, 아니면 다리 위에 있는 차들만 앞으로 한 칸씩 전진하면 된다.
#include<iostream>
#include<algorithm>
using namespace std;
int main(void) {
ios::sync_with_stdio(false);
cin.tie(0);
int n, w, L, nl[1010] = {}, wl[2000] = {};
cin >> n >> w >> L;
for (int i = 0; i < n; i++)
cin >> nl[i];
int t = 1, cW = nl[0], s = 0, l = 1, c = 0;
wl[0] = 1;
while (t++) {
// 다리위에있는애들 한 칸씩 전진
for (int i = s; i < n; i++) {
if (0 < wl[i] && wl[i] <= w){
wl[i]++;
if (wl[i] == w + 1){
cW -= nl[i];
wl[i] = 0;
s++;
c++;
}
}
}
// 새로운 애들을 다리 위로 올리자.
if (cW + nl[l] <= L) {
cW += nl[l];
wl[l] = 1;
l++;
}
if (c == n) {
cout << t;
break;
}
}
}
'Problem Solving > ICPC' 카테고리의 다른 글
[ICPC][BOJ] 13328 - Message Passing (0) | 2019.09.23 |
---|---|
[ICPC][BOJ] 13333 - 'Q-Index' (0) | 2019.09.23 |
[ICPC][BOJ] 8912 - Sales (0) | 2019.09.23 |
[ICPC][BOJ] 9093 - Word Reversal (0) | 2019.09.23 |
[ACM-ICPC][BOJ] 8896 - Rock Paper Scissors (0) | 2019.09.04 |