当前位置: 代码迷 >> 综合 >> CF1579E1 Permutation Minimization by Deque
  详细解决方案

CF1579E1 Permutation Minimization by Deque

热度:108   发布时间:2023-10-14 00:11:06.0

原题链接

题意

CF1579E1 Permutation Minimization by Deque

思路

主要考察一个双端队列的模拟。

代码

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;cin >> t;while (t -- ){
    int n, x;scanf("%d", &n);deque<int> q;scanf("%d", &x);q.push_back(x);for (int i = 2; i <= n; i ++ ){
    scanf("%d", &x);if (x <= q[0]) q.push_front(x);else q.push_back(x);} for (auto i : q){
    printf("%d ", i);}cout << endl;}return 0;
}

总结

双端队列

  相关解决方案