链接:https://www.nowcoder.com/acm/contest/141/C
来源:牛客网

Shuffle Cards

时间限制: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

输出 3 4 1 5 2
题目大意:1-n,m次操作,每次取下标为p及后s长度的串,将串移动至数组最前方,前面的跑到后面去

例如:1 2 3 4 5 操作2 3->串为2 3 4,串移到最前面,之前的首串后移变成2 3 4 1 5

#include<bits/stdc++.h>
#include<ext/rope>
using namespace std;
using namespace __gnu_cxx;
int main()
{int a,b,i,j,n,m;while(scanf("%d%d",&n,&m)!=EOF){rope<int>q;for(i=1;i<=n;i++) q.push_back(i);for(i=0;i<m;i++){scanf("%d%d",&a,&b);a--;q=q.substr(a,b)+q.substr(0,a)+q.substr(a+b,n-a-b);}for(i=0;i<n;i++)cout<<q.at(i)<<" ";}return 0;
}

Shuffle Cards(Rope大法)将一段区间的数字整体搬动相关推荐

  1. rope 实用把一段区间的数字整体搬到序列中的一段的时候用

    rope<int>test; test.push_back(x);//在末尾添加x for(i=1;i<=5;i++)q.push_back(i);//12345for(i=0;i& ...

  2. 牛客多校3 C-Shuffle Cards(rope大法解决数组分块)

    Shuffle Cards 链接:https://www.nowcoder.com/acm/contest/141/C 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 2 ...

  3. c++自带的可持久化平衡树?rope大法好!(超详细解答 + 5道例题讲解,可直接替代可持久化的线段树、并查集、平衡树!)

    整理的算法模板合集: ACM模板 目录 c++自带的可持久化平衡树?rope大法好! 1. 声明 2. 支持操作 char类型的rope int类型的rope 3. 具体的细节 4. "可持 ...

  4. 【每日训练】2020/11/9(Splay ?rope大法好!、数论、构造补图)

    整理的算法模板合集: ACM模板 目录 1. 牛客Shuffle Cards 2.CF992B Nastya Studies Informatics 3.CF990D Graph And Its Co ...

  5. C Shuffle Cards

     牛客网暑期ACM多校训练营(第三场)  C   Shuffle Cards 题目: 链接:https://www.nowcoder.com/acm/contest/141/C 来源:牛客网 时间限制 ...

  6. 牛客网暑期ACM多校训练营(第三场): C. Shuffle Cards(splay)

    链接:https://www.nowcoder.com/acm/contest/141/C 来源:牛客网 题目描述 Eddy likes to play cards game since there ...

  7. 【Rope大法好】【STL中丧心病狂的可持久化平衡树】

    曾经我不会写平衡树--于是在STL中乱翻--学到了pb_ds库中的SXBK的斐波那契堆.支持kth的set,和--ext/rope 先发一个官方的 说明 (鸣谢maoxiaohan1999): htt ...

  8. 线段树区间合并--询问某段区间内最长连续上升子序列即最长上升子串

    链接:https://www.nowcoder.com/acm/contest/158/B 来源:牛客网 最长区间 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他 ...

  9. 将一段区间的偶数分解为两个素数相加(Java)

    从键盘接收任意两个正整数,要求第一个正整数必须小于第二个正整数.然后把这两个数范围之内(包括这两个数)的所有偶数分解为两个素数之和,并输出每个偶数以及对应的两个素数 方法一 package day05 ...

最新文章

  1. 基础知识——类和文件和异常(六)
  2. mysql5.6之key_buffer_size优化设置
  3. 无人配送的Nuro再融5亿美元,为啥中国复刻者们没它这么火
  4. 根据mysql数据库日志恢复删除数据
  5. exfat linux 读写速度,Ubuntu / Xubuntu : 读写 exFAT 文件系统
  6. LNMP+FARM+DNS
  7. python强制转型,python2--python3如何转型
  8. 小程序 长按转发_小程序转发分享
  9. 计算机专业毕业设计题目大全
  10. 那些年我们一起追逐过的安全工具
  11. windows 开机自启动cmd文件
  12. 第七周--项目1-静态成员应用
  13. Delphi FastReport4.5安装说明
  14. 锁升级过程(偏向锁/轻量级锁/重量级锁)
  15. 竞价推广方案怎么写,这些点你get到了吗?
  16. 从51开始的单片机之旅(一)----流水灯、矩形键盘、电子时钟
  17. js输入关键词生成标签代码
  18. bt ct 计算机辅助翻译,计算机辅助翻译报告
  19. Keras深度学习实战——使用深度Q学习进行SpaceInvaders游戏
  20. 超级坦克大战1990 - 坦克大战超难版

热门文章

  1. PHP连接pda,OTG接口是什么
  2. 乱码翻译器在线翻译_GAL党的福音——开源生肉翻译器MisakaTranslator正式版发布...
  3. 自学python能干些什么副业-她把摄影当副业:月薪3000,副业收入上万
  4. python画条形图-python 中条形图绘制
  5. python怎么读取excel-python怎么从excel中读取数据?
  6. python读音检测-python – 一个音符的录音音频会产生多个发音时间
  7. 0基础学python做什么工作好-零基础自学多久Python可以找什么工作
  8. python工资一般多少-Python开发的工资一般多少
  9. python处理excel的优势-SAS、R、SPSS、python、excel五大软件的比较优势分析
  10. python必背入门代码-初学Python必背手册