본문 바로가기

USACO/Bronze

백준 5957 Cleaning the Dishes (USACO January 2011 Bronze 2번)

문제 링크: https://www.acmicpc.net/problem/5957

 

5957번: Cleaning the Dishes

Bessie and Canmuu are teaming up to wash the massive pile of N (1 <= N <= 10,000) dirty dishes left over after the CowMoose Festival. Bessie is washing the dishes; Canmuu will dry them. Each dish has a unique serial number in the range 1..N. At the beginni

www.acmicpc.net

STACK

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <bits/stdc++.h>
using namespace std;
 
int n;
stack<int> a, b, c;
 
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
 
    cin >> n;
    for(int i = n; i >= 1; i--)
        a.push(i);
 
    while(c.size() != n) {
        int u, v;
        cin >> u >> v;
        if(u == 1) {
            while(v--) {
                b.push(a.top());
                a.pop();
            }
        }
        else {
            while(v--) {
                c.push(b.top());
                b.pop();
            }
        }
    }
 
    while(!c.empty()) {
        cout << c.top() << '\n';
        c.pop();
    }
    return 0;
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter