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 | #pragma warning(disable: 4996) #include <stdio.h> #include <queue> #include <vector> #include <utility> #include <algorithm> using namespace std; int main() { int t, arr_len, num; queue<pair<int,int> > q; vector<int> rank; scanf("%d", &t); while (t--) { scanf("%d %d", &arr_len, &num); for(int i=0;i< arr_len;i++) { int tmp; scanf("%d", &tmp); q.push(make_pair(tmp, i)); rank.push_back(tmp); } // rank 순서 정렬해줌 sort(rank.begin(), rank.end()); int cnt = 0; while (1) { int cur = q.front().first; int cur_idx = q.front().second; int largest = rank.back(); // 뺄 순서일 경우 if (cur == largest) { q.pop(); rank.pop_back(); cnt++; // 내가 찾던 수인 경우 if (num == cur_idx) break; } // 뺄 순서가 아닌 경우 else { q.push(q.front()); q.pop(); } } printf("%d\n", cnt); while (q.empty() == false) q.pop(); while (rank.empty() == false) rank.pop_back(); } } | cs |
'알고리즘 > 시뮬레이션' 카테고리의 다른 글
1592 영식이와 친구들 (0) | 2020.01.15 |
---|---|
2979 트럭 주차 (0) | 2020.01.15 |
2164 카드2 (0) | 2020.01.15 |
1547 공 (0) | 2020.01.15 |
2161 카드1 (0) | 2020.01.15 |