返回顶部

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

  • 题意:有两个完全相同的排列,将其中一个的元素按相对顺序插入另外一个排列中,给你操作完的排列,求原排列.

  • 题解:感觉看看样例就能直接写了啊,直接遍历,用桶存数字个数,如果桶为空,直接输出即可.

  • 代码:

    int t;
    int n;
    vector<int> v;
    map<int,int> mp;
     
    int main() {
        ios::sync_with_stdio(false);cin.tie(0);
      	cin>>t;
      	 while(t--){
      	 	cin>>n;
      	 	mp.clear();
      	 	v.clear();
      	 	 for(int i=1;i<=2*n;++i){
      	 	 	int x;
      	 	 	cin>>x;
      	 	 	if(!mp[x]){
      	 	 		v.pb(x);
      	 	 	}
      	 	 	mp[x]++;
      	 	 }
      	 	 for(auto w:v){
      	 	 	cout<<w<<" ";
      	 	 }
      	 	 cout<<endl;
      	 }
    
        return 0;
    }
    
posted @ 2020-07-18 01:05  _Kolibri  阅读(124)  评论(0)    收藏  举报