반응형

문제 출처 :


https://www.acmicpc.net/problem/14612


알고리즘 분석 :


문제 해결에 필요한 사항

1. 구현


구현을 통해 간단히 해결 가능하다.


일단 문자열이 들어오는것이 order, complete, sort인데 앞 글자만 봐도 단어들이 다르기에 1글자로만 해결하도록 한다.


o, c, s로만 하도록 한다는 의미.


그리고 각자에 맞게 코드를 구현해주면 되고 벡터와 pair를 이용하면 좀 더 쉽게 해결이 가능하다.


이때 n제한이 작기 때문에 complete에서 그냥 순차탐색으로 complete시켜도 괜찮다.












소스 코드 : 


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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
 
using namespace std;
 
typedef pair<intint> pii;
 
vector<pii> vc;
 
int main()
{
    int n, m;
    scanf("%d %d"&n, &m);
 
    char str[10];
    for (int i = 0; i < n; i++)
    {
        scanf("%s", str);
 
        if (str[0== 'o')
        {
            int pos, time;
            scanf("%d %d"&pos, &time);
 
            vc.push_back({ time, pos });
            
            int len = vc.size();
 
            for (int i = 0; i < len; i++)
                printf("%d ", vc[i].second);
 
            printf("\n");
        }
 
        else if (str[0== 's')
        {
            sort(vc.begin(), vc.end());
 
            int len = vc.size();
 
            if (len == 0)
                printf("sleep");
 
            else
                for (int i = 0; i < len; i++)
                    printf("%d ", vc[i].second);
 
            printf("\n");
        }
        
        else
        {
            int pos;
            scanf("%d"&pos);
 
            int len = vc.size();
            for (int i = 0; i < len; i++)
                if (vc[i].second == pos)
                {
                    vc.erase(vc.begin() + i);
                    break;
                }
 
            len = vc.size();
 
            if (len == 0)
                printf("sleep");
 
            else
                for (int i = 0; i < len; i++)
                    printf("%d ", vc[i].second);
            
            printf("\n");
        }
    }
 
    return 0;
}
 
//                                                       This source code Copyright belongs to Crocus
//                                                        If you want to see more? click here >>
Crocus

반응형

'Applied > 알고리즘 문제풀이' 카테고리의 다른 글

[1849번] 순열  (0) 2017.06.07
[3020번] 개똥벌레  (0) 2017.06.06
[14553번] The Way  (2) 2017.06.05
[11058번] 크리보드  (0) 2017.06.01
[2512번] 예산  (0) 2017.05.30