日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

HDUOJ 6707 Shuffle Card

發布時間:2024/3/7 编程问答 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 HDUOJ 6707 Shuffle Card 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

HDUOJ 6707 Shuffle Card

題目鏈接

Problem Description

A deck of card consists of n cards. Each card is different, numbered from 1 to n. At first, the cards were ordered from 1 to n. We complete the shuffle process in the following way, In each operation, we will draw a card and put it in the position of the first card, and repeat this operation for m times.

Please output the order of cards after m operations.

Input

The first line of input contains two positive integers n and m.(1<=n,m<=1e5)

The second line of the input file has n Numbers, a sequence of 1 through n.

Next there are m rows, each of which has a positive integer si, representing the card number extracted by the i-th operation.

Output

Please output the order of cards after m operations. (There should be one space after each number.)

Sample Input

5 3 1 2 3 4 5 3 4 3

Sample Output

3 4 1 2 5

思維題,在線洗牌肯定會 T,因為沒有一個很好的數據結構可以完成此題。我們不妨換一種思維,把洗牌順序記錄下來,不難發現,最后一次洗的牌一定在第一張,倒數第二次在第二張,以此類推,我們標記一下洗過的牌,最后沒洗的保持原順序插入答案數組即可,AC代碼如下:

#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N=1e5+5; int n,m,a[N],op[N],vis[N]; vector<int>ans; int main(){scanf("%d%d",&n,&m);for(int i=1;i<=n;i++){scanf("%d",&a[i]);}for(int i=1;i<=m;i++) scanf("%d",&op[i]);for(int i=m;i>=1;i--){if(!vis[op[i]]){ans.push_back(op[i]);vis[op[i]]=1;}}for(int i=1;i<=n;i++){if(!vis[a[i]]) ans.push_back(a[i]);}for(auto i:ans) printf("%d ",i); }

總結

以上是生活随笔為你收集整理的HDUOJ 6707 Shuffle Card的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。