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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

2019中国大学生程序设计竞赛(CCPC)-网络选拔赛-第七题Shuffle Card

發布時間:2025/3/21 编程问答 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 2019中国大学生程序设计竞赛(CCPC)-网络选拔赛-第七题Shuffle Card 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

文章目錄

    • 1.大賽題目
    • 2.中文翻譯
    • 3.代碼案例
    • 4.解題思路
      • 4.1代碼舉例

1.大賽題目

Shuffle Card
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 6695 Accepted Submission(s): 2061

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<=105)

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

2.中文翻譯

洗牌。
時間限制:2000/1000毫秒(Java /其他)內存限制:65536/65536 K(Java /其他)
總提交量:6695份接受的提交量:2061份

問題

一副牌由N張牌組成。每一張牌都是不同的,編號從1到N。首先,牌是從1到N排列的。我們按照以下方式完成洗牌過程,在每一個操作中,我們將畫一張牌并將其放在第一張牌的位置上,然后重復操作m次。

請在M操作后輸出卡的順序。

輸入

輸入的第一行包含兩個正整數n和m。

輸入文件的第二行有n個數字,從1到n的序列。

接下來有m行,每行都有一個正整數si,表示第i個操作提取的卡號。

輸出

請在M操作后輸出卡的順序。(每個數字后面應該有一個空格。)

樣本輸入

5 3
1 2 3 4 5
3
4
3

樣本輸出

3 4 1 2 5

3.代碼案例

public class sixtest {public static void main(String args[]) {Scanner scanner = new Scanner(System.in);//n=5int n = scanner.nextInt();//m=3int m = scanner.nextInt();int A[] = new int[n];int out[] = new int[n];int B[] = new int[m];//輸入Afor(int i = 0;i<A.length;i++) {A[i] = scanner.nextInt();}//輸入Bfor(int i = 0;i<B.length;i++) {B[i] = scanner.nextInt();}//數組創造空間之后,默認每一個下標的值為0int Ex[] = new int [100010];int count = 0;//把要抽選的牌按照從后到前的順序裝進數組out中,重復的略過,然后再把剩余的裝進之后的數組下標for(int i = B.length-1; i >= 0; i--) {if(Ex[B[i]]==0) {out[count++] = B[i];//這里Ex[B[i]]等于幾都可以,只要不等于0Ex[B[i]] = 1;}}for(int i = 0;i<A.length;i++) {if(Ex[A[i]]==0) {out[count++] = A[i];}}for(int i = 0;i<out.length;i++) {System.out.print(out[i]+" ");}scanner.close();} }

4.解題思路

像下面這樣把要抽取的牌一張一張的放到最前面,后面的依次往后,可以抽相同的牌
->12345
->32145
->43125
->34125
把要抽選的牌按照從后到前的順序裝進數組out中,重復的略過,然后再把剩余的裝進剩余的數組下標

4.1代碼舉例

for(int i = B.length-1; i >= 0; i--) {if(Ex[B[i]]==0) {out[count++] = B[i];//這里Ex[B[i]]等于幾都可以,只要不等于0Ex[B[i]] = 1;} }

Ex[3] = 0->out[1] = 3->Ex[3] = 1
Ex[4] = 0->out[2] = 4->Ex[4] = 1
Ex[3] = 1 ->結束循環

for(int i = 0;i<A.length;i++) {if(Ex[A[i]]==0) {out[count++] = A[i];} }

Ex[1] = 0->out[3] = 1
Ex[2] = 0->out[4] = 2
Ex[3] = 1
Ex[4] = 1
Ex[5] = 0->out[5] = 5

總結

以上是生活随笔為你收集整理的2019中国大学生程序设计竞赛(CCPC)-网络选拔赛-第七题Shuffle Card的全部內容,希望文章能夠幫你解決所遇到的問題。

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