-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1021_회전하는큐.cpp
73 lines (62 loc) · 1.06 KB
/
1021_회전하는큐.cpp
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
#include<iostream>
#include<deque>
using namespace std;
int deSize;
int N;
int findNum;
int result = 0;
int leftNum, rightNum;
deque<int> de;
deque<int> tLeftDeque;
deque<int> tRightDeque;
int main(void)
{
cin >> deSize >> N;
for(int i = 1; i <= deSize; i++)
{
de.push_back(i);
}
for (int i = 0; i < N; i++)
{
leftNum = 0;
rightNum = 0;
cin >> findNum;
while (1)
{
if (de.front() == findNum)
{
de.pop_front();
break;
}
else
{
tLeftDeque = de;
while (tLeftDeque.front() != findNum)
{
leftNum++;
tLeftDeque.push_back(tLeftDeque.front());
tLeftDeque.pop_front();
}
tRightDeque = de;
while (tRightDeque.front() != findNum)
{
rightNum++;
tRightDeque.push_front(tRightDeque.back());
tRightDeque.pop_back();
}
if (leftNum > rightNum)
{
de = tRightDeque;
result += rightNum;
}
else
{
de = tLeftDeque;
result += leftNum;
}
}
}
}
cout << result;
return 0;
}