Skip to content

Commit

Permalink
4차시 업로드
Browse files Browse the repository at this point in the history
  • Loading branch information
YIM2UL2ET committed Feb 21, 2024
1 parent a81d9db commit 9570c47
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
3 changes: 2 additions & 1 deletion YIM2UL2ET/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
|:----:|:---------:|:----:|:-----:|:----:|
| 1차시 | 2024.02.12 | 그리디 | [BOJ 18310](https://www.acmicpc.net/problem/18310) | [BOJ 18310 풀이](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/3) |
| 2차시 | 2024.02.15 | 그리디 | [BOJ 1263](https://www.acmicpc.net/problem/1263) | [BOJ 1449 풀이](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/7) |
| 3차시 | 2024.02.18 | 자료구조 | [BOJ 2504](https://www.acmicpc.net/problem/2504) | [BOJ 2504 풀이](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/9) |
| 3차시 | 2024.02.18 | 스택 | [BOJ 2504](https://www.acmicpc.net/problem/2504) | [BOJ 2504 풀이](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/9) |
| 4차시 | 2024.02.21 || [BOJ 1021](https://www.acmicpc.net/problem/1021) | [BOJ 1021 풀이](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/12) |
---
45 changes: 45 additions & 0 deletions YIM2UL2ET/덱/4차시 - BOJ 1021.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include <iostream>
#include <algorithm>
#include <deque>

int main(void)
{
int n, m, k, idx, result;
std::deque <int> dq;

std::cin >> n >> m;
for (int i = 0; i < n;) {
dq.push_back(++i);
}

result = 0;
for (int i = 0; i < m; i++) {
std::cin >> k;

std::deque <int> :: iterator iter;
iter = std::find(dq.begin(), dq.end(), k);
idx = std::distance(dq.begin(), iter);

if (idx < dq.size() - idx) {
result += idx;
for (int j = 0; j < idx; j++) {
int temp = dq.front();
dq.pop_front();
dq.push_back(temp);
}
}
else {
result += dq.size() - idx;
for (int j = 0; j < dq.size() - idx; j++) {
int temp = dq.back();
dq.pop_back();
dq.push_front(temp);
}
}

dq.pop_front();
}

std::cout << result;
return 0;
}

0 comments on commit 9570c47

Please sign in to comment.