Codeforces Round #656 (Div. 3) B. Restore the Permutation by Merger

题目链接:https://codeforces.com/contest/1385/problem/B

题意

有两个大小为 $n$ 的相同的排列,每次从二者或二者之一的首部取元素排入新的数组,给出这个大小为 $2n$ 的数组,找到原先的排列。

题解

忽略所有第二次出现的数即可。

代码

#include <bits/stdc++.h>
using namespace std;

void solve() {
    int n; cin >> n;
    map<int, bool> vis;
    for (int i = 0; i < 2 * n; i++) {
        int x; cin >> x;
        if (!vis[x]) {
            cout << x << ' ';
            vis[x] = true;
        }
    }
    cout << "
";
}

int main() {
    int t; cin >> t;
    while (t--) solve();
}
原文地址:https://www.cnblogs.com/Kanoon/p/13334251.html