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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

C Shuffle Cards

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

?牛客網暑期ACM多校訓練營(第三場)? C? ?Shuffle Cards

題目:

鏈接:https://www.nowcoder.com/acm/contest/141/C
來源:牛客網

時間限制:C/C++ 1秒,其他語言2秒
空間限制:C/C++ 262144K,其他語言524288K
Special Judge, 64bit IO Format: %lld
題目描述
Eddy likes to play cards game since there are always lots of randomness in the game. For most of the cards game, the very first step in the game is shuffling the cards. And, mostly the randomness in the game is from this step. However, Eddy doubts that if the shuffling is not done well, the order of the cards is predictable!

To prove that, Eddy wants to shuffle cards and tries to predict the final order of the cards. Actually, Eddy knows only one way to shuffle cards that is taking some middle consecutive cards and put them on the top of rest. When shuffling cards, Eddy just keeps repeating this procedure. After several rounds, Eddy has lost the track of the order of cards and believes that the assumption he made is wrong. As Eddy's friend, you are watching him doing such foolish thing and easily memorizes all the moves he done. Now, you are going to tell Eddy the final order of cards as a magic to surprise him.

Eddy has showed you at first that the cards are number from 1 to N from top to bottom.

For example, there are 5 cards and Eddy has done 1 shuffling. He takes out 2-nd card from top to 4-th card from top(indexed from 1) and put them on the top of rest cards. Then, the final order of cards from top will be [2,3,4,1,5].
輸入描述:
The first line contains two space-separated integer N, M indicating the number of cards and the number of shuffling Eddy has done.
Each of following M lines contains two space-separated integer pi, si indicating that Eddy takes pi-th card from top to (pi+si-1)-th card from top(indexed from 1) and put them on the top of rest cards.


1 ≤ N, M ≤ 105
1 ≤ pi ≤ N
1 ≤ si ≤ N-pi+1
輸出描述:
Output one line contains N space-separated integers indicating the final order of the cards from top to bottom.
示例1
輸入
復制
5 1
2 3
輸出
復制
2 3 4 1 5
示例2
輸入
復制
5 2
2 3
2 3
輸出
復制
3 4 1 2 5
示例3
輸入
復制
5 3
2 3
1 4
2 4
輸出
復制
3 4 1 5 2

思路:

  rope可當做可持久化平衡樹,適用于大量、冗長的串操作

 基本操作:

? ? ? ?1)運算符:rope支持operator += -= + - < ==

  2)輸入輸出:可以用<<運算符由輸入輸出流讀入或輸出。

  3)長度/大小:調用length(),size()都可以哦

  4)插入/添加等:

  push_back(x);//在末尾添加x

  insert(pos,x);//在pos插入x,自然支持整個char數組的一次插入

  erase(pos,x);//從pos開始刪除x個

  copy(pos,len,x);//從pos開始到pos+len為止用x代替

  replace(pos,x);//從pos開始換成x

  substr(pos,x);//提取pos開始x個

  at(x)/[x];//訪問第x個元素

代碼:

#include<cstdio> #include<ext/rope> //固定寫法 using namespace std; using namespace __gnu_cxx; //固定寫法 rope<int> ss; //實質是可持久化平衡樹int n,m; int main() {scanf("%d%d",&n,&m);for(int i=1; i<=n; i++) ss.push_back(i); //放入元素(1~n)while(m--){int p,s;scanf("%d%d",&p,&s);ss = ss.substr(p-1,s)+ss.substr(0,p-1)+ss.substr(p+s-1,n-p-s+1); //重新組合三個區間 substr(起始位置,區間長度) }for(int i=0; i<n; i++){printf("%d",ss[i]);if(i==n-1)puts("");else printf(" ");}return 0; }

?

轉載于:https://www.cnblogs.com/longl/p/9381126.html

總結

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

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