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
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <queue>
#include <vector>
#include <deque>
#include <stdio.h>
 
using namespace std;
 
bool isMax(deque<int> d) {
    //vec의 첫번째 값이 가장 크면 true 아니면 false 반환
    deque<int>::iterator iter = d.begin();
    int current = *iter;
    iter++;
 
    bool ret = true;
    for (iter; iter != d.end(); iter++) {
        if (*iter > current) {
            ret = false;
            break;
        }
    }
 
    return ret;
}
 
int main() {
    int t;
    scanf("%d"&t);
    //cin >> t;
    for (int tc = 0; tc < t; tc++) {
        int n, m;
        scanf("%d %d"&n, &m);
        //cin >> n >> m;
 
        int order = 0;  //순서
 
        queue<int> q;
        deque<int> importanceD(n, 0);  //중요도. 앞에서 pop 해야되므로 데크
        for (int i = 0; i < n; i++) {
            q.push(i);
            scanf("%d"&importanceD[i]);
        }
 
        while (true) {
            if (isMax(importanceD)) {
                //가장 크면
                if (q.front() == m) {  //n번째 수면
                    order++;
                    break;
                }
                q.pop();
                order++;
                importanceD.pop_front();
            }
            else {
                //맨 앞 중요도가 가장 큰거 아니면 뒤로 보내기
                q.push(q.front());  
                q.pop();
 
                importanceD.push_back(importanceD.front());
                importanceD.pop_front();
            }
        }
        printf("%d\n", order);
    }
    return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs

 

 

'Baekjoon' 카테고리의 다른 글

[#1992] 쿼드트리  (0) 2020.03.16
[#2630] 색종이 만들기  (0) 2020.03.16
[#11866] 요세푸스 문제 0  (0) 2020.03.15
[#2164] 카드 2  (0) 2020.03.15
[#18258] 큐 2  (0) 2020.03.15

+ Recent posts