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. 《OD学微信开发》微信小程序入门示例

    官网地址: https://mp.weixin.qq.com/debug/wxadoc/dev/ 一.文件结构 小程序包含一个描述整体程序的 app 和多个描述各自页面的 page. .js后缀的是脚 ...

  2. CF17E Palisection(回文自动机)

    题意翻译 给定一个长度为n的小写字母串.问你有多少对相交的回文子 串(包含也算相交) . 输入格式 第一行是字符串长度n(1<=n<=2*10^6),第二行字符串 输出格式 相交的回文子串 ...

  3. MCP|DYM|Quantitative mass spectrometry to interrogate proteomic heterogeneity in metastatic lung adenocarcinoma and validate a novel somatic mutation CDK12-G879V (利用定量质谱探究转移性肺腺瘤的蛋白质组异质性及验证新体细胞突变)

    文献名:Quantitative mass spectrometry to interrogate proteomic heterogeneity in metastatic lung adenoca ...

  4. UVA12230 过河 Crossing Rivers

    题目描述 一个人每天需要从家去往公司,然后家与公司的道路是条直线,长度为 \(D\). 同时路上有 \(N\)条河,给出起点和宽度\(W_i\) , 过河需要乘坐速度为\(V_i\) 的渡船; 船在河 ...

  5. has been blocked by CORS policy: Request header field authorization is not allowed by Access-Control-Allow-Headers in preflight response.

    https://www.cnblogs.com/caimuqing/p/6733405.html // TODO 支持跨域访问 response.setHeader("Access-Cont ...

  6. STP-15-PortFast端口

    PortFast是大家熟知的传统STP和PVST+改进特性,它也是RSTP和MST中标准化的增强特性.实质上,它定义了个一个边界端口.边界端口在启用之后立刻进入转发状态,不产生拓扑变化事件,不会因为处 ...

  7. JavaScript刷新页面,不重复提交

    location.replace(location.href);//刷新页面,不重复提交

  8. Eclipse中mybatis的xml文件没有提示,出现the file cannot be validated as the XML definition.....

    1.下载dtd文件 2.在eclipse中配置本地dtd文件: Window->Preferences->XML->XML Catalog->User Specified En ...

  9. D. Time to Raid Cowavans 分块暴力,感觉关键在dp

    http://codeforces.com/contest/103/problem/D 对于b大于 sqrt(n)的,暴力处理的话,那么算出每个的复杂度是sqrt(n),就是把n分成了sqrt(n)段 ...

  10. Java面向对象_单例设计模式

    单例设计模式:保证一个类仅有一个实例,并提供一个访问它的全局访问点 1.构造方法私有化 2.声明一个本类对象 3.给外部提供一个静态方法获取对象实例 两种实现方式:饿汉式和懒汉式 何种情况下使用呢?当 ...