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. Solr 6.7学习笔记(02)-- 配置文件 managed-schema (schema.xml)(2)

    接上篇    2. <dynamicField> 为满足前辍或后辍的一些字段提供统一的定义.如<dynamicField name="*_s" index=&qu ...

  2. VS2012打包部署教程

    前言 通常我们只是写一些系统,然后想要运行功能的时候就打开代码点击启动,这样只适用于开发人员或者局部开发人员这样做,软件开发的大多数意义上就是拿出开发的软件让用户放心的去点.用户无需知道代码,无需知道 ...

  3. 分层图最短路【bzoj2834】: 回家的路

    分层图最短路[bzoj2834]: 回家的路 题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=2834 这道题难在建边. 自己写的时候想到了 ...

  4. ShardingJDBC(一)-转载

    Sharding-JDBC:垂直拆分怎么做? 原创: 尹吉欢 猿天地 今天 经过读写分离的优化后,小王可算是轻松了一段时间,读写分离具体的方案请查看这篇文章:Sharding-JDBC:查询量大如何优 ...

  5. [USACO08JAN]跑步Running dp

    题目描述 The cows are trying to become better athletes, so Bessie is running on a track for exactly N (1 ...

  6. Swift几行代码解决UITableView空数据视图问题

    tableView空数据问题 一般项目中tableView若数据为空时会有一个提示示意图 为了更好的管理这种提示示意图,笔者利用extension进行了简单的拓展 解决思路 利用swift面向协议的特 ...

  7. Hadoop_配置Hadoop开发环境(Eclipse)

    通常我们可以用Eclipse作为Hadoop程序的开发平台. 1)  下载Eclipse 下载地址:http://www.eclipse.org/downloads/ 根据操作系统类型,选择合适的版本 ...

  8. redmine迁移

    (redmine使用的是bitnamiredmine一键安装,环境为apache+mysql+php) 在新环境中一键安装bitnamiredmine,安装完后,执行下面操作 1.备份原环境数据库,恢 ...

  9. jquery——选项卡

    下面是闭包做选项卡: <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...

  10. 获取跨域请求的自定义的response headers

    一般情况下,使用ajax的getAllResponseHeaders这个方法只能得到response headers中的content-type的信息,其他服务器端放入response header中 ...