C: Shuffle Cards

时间限制: 1 Sec  内存限制: 128 MB
提交: 3  解决: 3
[提交] [状态] [讨论版] [命题人:admin]

题目描述

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.

样例输入

5 1
2 3

样例输出

2 3 4 1 5

使用rope(高效字符串处理数据结构)这种骚操作!

AC代码:

 #include<bits/stdc++.h>
#include <ext/rope>
using namespace std;
using namespace __gnu_cxx;
rope<int>ro;
int main()
{
int n,m;
scanf("%d %d",&n,&m);
for(int i=; i<=n; i++)
{
ro.push_back(i);
}
int a,b;
while(m--)
{
scanf("%d %d",&a,&b);
ro=ro.substr(a-,b)+ro.substr(,a-)+ro.substr(a+b-,n-a-b+);
}
for(int i=; i<n-; i++)
{
printf("%d ",ro[i]);
}
printf("%d\n",ro[n-]);
}

操作:
test.push_back(x);//在末尾添加x

test.insert(pos,x);//在pos插入x  

test.erase(pos,x);//从pos开始删除x个

test.copy(pos,len,x);//从pos开始到pos+len为止用x代替

test.replace(pos,x);//从pos开始换成x

test.substr(pos,x);//提取pos开始x个

test.at(x)/[x];//访问第x个元素

“rope的复制:

rope<char> *his[maxn];

his[0]=new rope<char>();

his[i]=new rope<char>(*his[i-1]);

his[i]->push_back(x);

Shuffle Cards的更多相关文章

  1. [CareerCup] 18.2 Shuffle Cards 洗牌

    18.2 Write a method to shuffle a deck of cards. It must be a perfect shuffle—in other words, each of ...

  2. 2018牛客网暑期ACM多校训练营(第三场) H - Shuffle Cards - [splay伸展树][区间移动][区间反转]

    题目链接:https://www.nowcoder.com/acm/contest/141/C 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524288K ...

  3. (第三场) C Shuffle Cards 【STL_rope || splay】

    题目链接:https://www.nowcoder.com/acm/contest/141/C 题目描述 Eddy likes to play cards game since there are a ...

  4. 牛客网暑期ACM多校训练营(第三场) C Shuffle Cards 平衡树 rope的运用

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

  5. 2018牛客网暑期ACM多校训练营(第三场)C Shuffle Cards(可持久化平衡树/splay)

    题意 牌面初始是1到n,进行m次洗牌,每次抽取一段放到最前面.求最后的序列. 分析 神操作!!!比赛时很绝望,splay技能尚未点亮,不知道怎么用. 殊不知,C++库里有rope神器,即块状链表. 基 ...

  6. 牛客网多校训练第三场 C - Shuffle Cards(Splay / rope)

    链接: https://www.nowcoder.com/acm/contest/141/C 题意: 给出一个n个元素的序列(1,2,...,n)和m个操作(1≤n,m≤1e5),每个操作给出两个数p ...

  7. Shuffle Cards(牛客第三场+splay)

    题目: 题意:将1~n的数进行m次操作,每次操作将第pi位到pi+si-1位的数字移到第一位,求最后的排列. 思路:现在还没不会写splay,在知道这是splay模板题后找了一波别人的模板,虽然过了, ...

  8. 2018牛客多校第三场 C.Shuffle Cards

    题意: 给出一段序列,每次将从第p个数开始的s个数移到最前面.求最终的序列是什么. 题解: Splay翻转模板题.存下板子. #include <bits/stdc++.h> using ...

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

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

随机推荐

  1. DMZ主机

    DMZ称为"隔离区",也称"非军事化区".为了解决安装防火墙后外部网络不能访问内部网络服务器的问题,而设立的一个非安全系统与安全系统之间的缓冲区.这个缓冲区位于 ...

  2. Mol Cell Proteomics. |马臻| psims-一个用于编写HUPO-PSI标准下的mzML和mzIdentML的python库

    大家好,本周分享的是发表在MCP(MOLECULAR&CRLLULAR PROTEOMICS)上的一篇关于质谱数据处理和识别的文章,题目是psims - A Declarative Write ...

  3. 动手写一个简单版的谷歌TPU-矩阵乘法和卷积

    谷歌TPU是一个设计良好的矩阵计算加速单元,可以很好的加速神经网络的计算.本系列文章将利用公开的TPU V1相关资料,对其进行一定的简化.推测和修改,来实际编写一个简单版本的谷歌TPU.计划实现到行为 ...

  4. ldap第二天-yum安装LDAP + phpLDAPadmin

    1.安装LDAP服务器和客户端,migrationtools工具包 yum install -y openldap-servers openldap-clients migrationtools 2. ...

  5. screen命令常用参数使用

    screen简要说明 screen 会话命令可以保持本地和服务器断开后,程序继续在服务器上运行,并且运行结束后,输出最后的结果.功能结果相当于 nohup command &,但是功能远比no ...

  6. python大战机器学习——半监督学习

    半监督学习:综合利用有类标的数据和没有类标的数据,来生成合适的分类函数.它是一类可以自动地利用未标记的数据来提升学习性能的算法 1.生成式半监督学习 优点:方法简单,容易实现.通常在有标记数据极少时, ...

  7. js中的onclick事件传参需要注意的问题

    如果参数是数值类型可以直接传,如果是字符串类型需要在字符串前后加上双引号,双引号需要转义 如 onclick="test(0)";  直接传值 参数为数值 onclick=&quo ...

  8. Zookeeper问题汇总

    1. 遗留问题 a). zookeeper集群如何保证请求的均匀分布? 2. ZK概念澄清 2.1 ZK节点类型 CreateMode.PERSISTENT //持久节点,该节点客户端断开后不会删除 ...

  9. Spring Cloud微服务初探

    学习初衷 因为加了不少优秀的知识星球,结交了更多的小伙伴,加了更多的群,每每在自我介绍的时候,都说自己是Android & Java攻城狮. 然鹅,有的小伙伴就来问了,你是搞Java的,那对S ...

  10. jQuery 方法 属性

    Attribute:$("p").addClass(css中定义的样式类型); 给某个元素添加样式$("img").attr({src:"test.j ...