1365: Play with Chain

Time Limit: 5 Sec  Memory Limit: 128 MB
Submit:
21  Solved: 5
[Submit][Status][Web
Board
]

Description

YaoYao is fond of playing his chains. He has
a chain containing n diamonds on it. Diamonds are numbered from 1 to n.
At
first, the diamonds on the chain is a sequence: 1, 2, 3, …, n.
He will
perform two types of operations:

CUT a b c: He
will first cut down the chain from the ath diamond to the
bth diamond. And then insert it after the cth diamond on
the remaining chain.
For example, if n=8, the chain is: 1 2 3 4 5 6 7 8; We
perform “CUT 3 5 4”, Then we first cut down 3 4 5, and the remaining chain would
be: 1 2 6 7 8. Then we insert “3 4 5” into the chain before 5th
diamond, the chain turns out to be: 1 2 6 7 3 4 5 8.

FLIP a
b:
We first cut down the chain from the ath diamond to
the bth diamond. Then reverse the chain and put them back to the
original position.
For example, if we perform “FLIP 2 6” on the chain: 1 2 6
7 3 4 5 8. The chain will turn out to be: 1 4 3 7 6 2 5 8

He wants to
know what the chain looks like after perform m operations. Could you help him?

Input

There will be multiple test cases in a test
data.
For each test case, the first line contains two numbers: n and m (1≤n,
m≤3*100000), indicating the total number of diamonds on the chain and the number
of operations respectively.
Then m lines follow, each line contains one
operation. The command is like this:

CUT a b c   // Means a CUT operation, 1 ≤
a ≤ b ≤ n, 0≤ c ≤ n-(b-a+1).
FLIP a b        // Means a FLIP operation, 1 ≤ a
< b ≤ n.

The input ends up with two negative
numbers, which should not be processed as a case.

Output

For each test case, you should print a line
with n numbers. The ith number is the number of the ith
diamond on the chain.

Sample Input

8 2
CUT 3 5 4
FLIP 2 6
-1 -1

Sample Output

1 4 3 7 6 2 5 8
 #include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std; struct node
{
int num;
struct node *next;
struct node *father;
};
struct node *head;
void mem(struct node *p)
{
p->num=;
p->next=NULL;
p->father=NULL;
}
void CUT(int l,int r,int k,int n)
{
if(k==l-)return;
if(l==&&r==n)return ;
struct node *p,*q,*st,*ed,*hxl;
int i,cur;
if(k<l) cur=r;
else
{
cur=r-l++k;
k=cur;
}
p=head;
for(i=;i<=cur&&p!=NULL;i++)
{
p=p->next;
if(i==l) st=p;
if(i==r) ed=p;
if(i==k) hxl=p;
}
if(k==) hxl=head;
p=st->father;
q=ed->next;
p->next=q;
if(q!=NULL) q->father=p; p=hxl->next;
ed->next=hxl->next;
if(p!=NULL) p->father=ed; hxl->next=st;
st->father=hxl;
}
void FLIP(int l,int r)
{
int i,tmp,tom;
struct node *st,*ed,*q;
q=head;
for(i=;i<=r;i++)
{
q=q->next;
if(i==l) st=q;
if(i==r) ed=q;
}
tom=(r-l+)/;
while(tom--)
{
tmp=st->num;
st->num=ed->num;
ed->num=tmp; st=st->next;
ed=ed->father;
}
}
int main()
{
int n,m,i;
int l,r,k;
char cur[];
struct node *p,*q;
while(scanf("%d%d",&n,&m)>)
{
if(n==-&&m==-)break;
head=(struct node*)malloc(sizeof(struct node));
mem(head);
p=head;
for(i=;i<=n;i++)
{
q=(struct node*)malloc(sizeof(struct node));
q->num=i;
q->next=p->next;
p->next=q;
q->father=p;
p=q;
}
getchar();
while(m--)
{
scanf("%s",cur);
if(cur[]=='C')
{
scanf("%d%d%d",&l,&r,&k);
CUT(l,r,k,n);
}
else if(cur[]=='F')
{
scanf("%d%d",&l,&r);
FLIP(l,r);
}
}
p=head;
for(i=;i<=n;i++)
{
q=p;
p=p->next;
free(q);
printf("%d",p->num);
if(i!=n)printf(" ");
else printf("\n");
}
free(p);
}
return ;
}
 

csu 1365 双向链表模拟超时的更多相关文章

  1. csu - 1537: Miscalculation (模拟题)

    http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1537 因为给出的式子是必定合法的,只要用两个栈分别保存符号和数字.算出答案后和从左至右算的答案比对 ...

  2. ACM/ICPC 之 用双向链表 or 模拟栈 解“栈混洗”问题-火车调度(TSH OJ - Train)

    本篇用双向链表和模拟栈混洗过程两种解答方式具体解答“栈混洗”的应用问题 有关栈混洗的定义和解释在此篇:手记-栈与队列相关 列车调度(Train) 描述 某列车调度站的铁道联接结构如Figure 1所示 ...

  3. fiddler模拟timeout超时场景

    fiddler模拟网络超时: 用fiddler模拟网络请求超时 最近要测试程序对cgi 请求超时的兼容,所以就需要模拟超时,第一个想到的就是fiddler工具,说一下具体的做法: Rules -> ...

  4. 2014-11-3 NOIP模拟赛3

    字符串 string.pas/c/cpp 1S/256MB [题目描述] 现在给一个字符串,你要做的就是当这个字符串中存在两个挨着的字符是相同的时就将这两个字符消除.需要注意的是,当把这两个字符消除后 ...

  5. zuul超时问题

    转载:http://blog.csdn.net/tianyaleixiaowu/article/details/78772269 是这样的,今天碰到了微服务响应超时问题,而且超时时间特别短,2秒就超时 ...

  6. Zuul超时问题,微服务响应超时,zuul进行熔断

    天碰到了微服务响应超时问题,而且超时时间特别短,2秒就超时,zuul就走熔断了. 我采用zuul作为网关,根据不同的访问路径进行微服务的路由,譬如有个服务是user,我访问user服务的某个接口时,该 ...

  7. HDU 6215 2017Brute Force Sorting 青岛网络赛 队列加链表模拟

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6215 题意:给你长度为n的数组,定义已经排列过的串为:相邻两项a[i],a[i+1],满足a[i]&l ...

  8. 怎样用Fiddler模拟网络超时

    转自:http://materliu.github.io/all/web/2014/04/28/fiddler-timeout.html   用fiddler模拟网络请求超时 用fiddler模拟网络 ...

  9. SpringCloud之Feign 负载均衡请求超时时间

    版本声明: SpringCloud:Greenwich.SR4 SpringBoot:2.1.9.RELEASE Feign调用服务的默认时长是1秒钟,也就是如果超过1秒没连接上或者超过1秒没响应,那 ...

随机推荐

  1. java修饰符顺序

    Modifiers should be declared in the correct order (squid:ModifiersOrderCheck) Code smell Minor The J ...

  2. AutoCad2012新增类AcRxVariablesDictionary 可以获取所有变量名和值

    //AutoCad2012新增类 获取所有变量名和值 AcRxVariablesDictionary *dic=AcRxVariablesDictionary::get(); const AcArra ...

  3. C#取得控制台应用程序的根目录方法

    如有雷同,不胜荣幸,若转载,请注明 取得控制台应用程序的根目录方法1:Environment.CurrentDirectory 取得或设置当前工作目录的完整限定路径2:AppDomain.Curren ...

  4. GPS坐标转百度地图坐标

    百度地图提供了相关API:BMap.Convertor.translate, 但是使用上存在部分限制:1.次数限制:2.异步回调 可以用如下方法: /** * 地图位置计算工具(将GPS坐标转换成百度 ...

  5. iOS9下UICollectionViewCell的awakeFromNib问题

    最近项目测试出一个隐藏已久的bug,经过多番测试,发现在iOS9下自定义的一个UICollectionViewCell只走一次awakeFromNib. 具体情况是,项目中有一个控制器用到了自定义的U ...

  6. leetcode-91-解码方法(动态规划和递归两种解法)

    题目描述: 一条包含字母 A-Z 的消息通过以下方式进行了编码: 'A' -> 1 'B' -> 2 ... 'Z' -> 26 给定一个只包含数字的非空字符串,请计算解码方法的总数 ...

  7. leetcode-852-山脉数组的峰顶索引

    题目描述: 我们把符合下列属性的数组 A 称作山脉: A.length >= 3 存在 0 < i < A.length - 1 使得A[0] < A[1] < ... ...

  8. STM32-RS232通信软硬件实现

    OS:Windows 64 Development kit:MDK5.14 IDE:UV4 MCU:STM32F103C8T6/VET6 AD:Altium Designer 18.0.12 1.RS ...

  9. python学习,day4:装饰器的使用示例

    ---恢复内容开始--- 装饰器:本质是函数,(装饰其他函数)就是为其他函数添加附加功能 装饰器有其独特的原则:1.不能修改被装饰的函数的源代码 2.不能修改被装饰的函数的调用方式 例子 import ...

  10. P4177 [CEOI2008]order

    传送门 答案等于总工作价值减去最小失去的价值 考虑构建最小割模型 在 $S$割 的点表示选,在 $T$割 的点表示不选 对于机器(编号从 $n+1$ 到 $n+m$) $n+i$,连边 $(n+i,T ...