Game Develop

[Algorithm] Baekjoon 1966번 : 프린터큐 본문

Algorithm/Baekjoon

[Algorithm] Baekjoon 1966번 : 프린터큐

MaxLevel 2024. 6. 22. 23:57

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

 

 

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
84
85
86
87
88
89
90
91
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <queue>
#include <functional>
#include <sstream>
#include <memory.h>
#include <deque>
#include <set>
#include <unordered_map>
#include <stack>
#include <numeric>
#include <climits>
#include <bitset>
#include <cmath>
 
using namespace std;
 
int t, n, m;
int arr[101= { 0 };
 
 
 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 
    cin >> t;
 
    vector<int> answers;
 
    while (t--)
    {
        cin >> n >> m;
 
        deque<pair<int,int>> dq;
        for (int i = 0; i < n; ++i)
        {
            int num;
            cin >> num;
            dq.push_back({ i,num });
        }
 
        int printCount = 0;
 
        while (1)
        {
            int curIndex = dq.front().first;
            int curNum = dq.front().second;
            dq.pop_front();
 
            bool check = false;
 
            for (int i = 0; i < dq.size(); ++i)
            {
                if (dq[i].second > curNum)
                {
                    check = true;
                    break;
                }
            }
 
            if (check)
            {
                dq.push_back({ curIndex,curNum });
            }
            else // 출력
            {
                ++printCount;
 
                if (curIndex == m)
                {
                    answers.push_back(printCount);
                    break;
                }
            }
        }
    }
 
    for (int i = 0; i < answers.size(); ++i)
    {
        printf("%d\n", answers[i]);
    }
}
 
 
cs

 

주어진 그대로 풀면 된다. 거의 구현문제?

덱을 쓰면 정말 편하게 할 수 있다.