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. asp代码审计

    今天给大家带来的是asp程序的代码审计,asp和aspx代码审计来说,有很多相同的地方. 正好今天要交任务,最近的目标站的子域名使用了这个cms,但是版本不一定是这个,好累. 本文作者:i春秋签约作家 ...

  2. Markdown入门简介

    参考 http://sspai.com/25137 作者: Te_Lee 文章来源: 少数派 Markdown入门简介(使用工具Haroopad) 一.使用的工具----haroopad(http:/ ...

  3. docker微服务部署之:一,搭建Eureka微服务项目

    先说明一下docker需要搭建的微服务的基本情况: 项目情况:一个demo_parent项目,下面三个子模块:demo_eureka(eureka服务).demo_article(文章服务).demo ...

  4. 使用selenium的WebDriver和ChromeDriver实现UI自动化

    下载chromedriver chromedriver与chrome的对应关系表:http://blog.csdn.net/huilan_same/article/details/51896672 下 ...

  5. SVN服务器端环境搭建步骤

    5.1 安装服务器端程序 yum install -y subversion 5.2 创建并配置版本库 创建版本库目录 mkdir -p /var/svn/repository 在版本库目录下创建具体 ...

  6. python之守护进程

    主进程创建子进程,然后将该进程设置成守护自己的进程,守护进程就好比崇祯皇帝身边的老太监,崇祯皇帝已死老太监就跟着殉葬了. 关于守护进程需要强调两点: 其一:守护进程会在主进程代码执行结束后就终止 其二 ...

  7. 南昌网络赛 Distance on the tree 主席树+树剖 (给一颗树,m次查询ui->vi这条链中边权小于等于ki的边数。)

    https://nanti.jisuanke.com/t/38229 题目: 给一颗树,m次查询ui->vi这条链中边权小于等于ki的边数. #include <bits/stdc++.h ...

  8. Vue 混入(mixins)

    详细参考官方文档 基础 混入 (mixins) 是一种分发 Vue 组件中可复用功能的非常灵活的方式.混入对象可以包含任意组件选项.当组件使用混入对象时,所有混入对象的选项将被混入该组件本身的选项. ...

  9. Python3 print()函数sep,end,file参数用法练习

    来自builtins.py:def print(self, *args, sep=' ', end='\n', file=None): # known special case of print &q ...

  10. java 并发编程——Thread 源码重新学习

    Java 并发编程系列文章 Java 并发基础——线程安全性 Java 并发编程——Callable+Future+FutureTask java 并发编程——Thread 源码重新学习 java并发 ...