csu 1365 双向链表模拟超时
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 双向链表模拟超时的更多相关文章
- csu - 1537: Miscalculation (模拟题)
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1537 因为给出的式子是必定合法的,只要用两个栈分别保存符号和数字.算出答案后和从左至右算的答案比对 ...
- ACM/ICPC 之 用双向链表 or 模拟栈 解“栈混洗”问题-火车调度(TSH OJ - Train)
本篇用双向链表和模拟栈混洗过程两种解答方式具体解答“栈混洗”的应用问题 有关栈混洗的定义和解释在此篇:手记-栈与队列相关 列车调度(Train) 描述 某列车调度站的铁道联接结构如Figure 1所示 ...
- fiddler模拟timeout超时场景
fiddler模拟网络超时: 用fiddler模拟网络请求超时 最近要测试程序对cgi 请求超时的兼容,所以就需要模拟超时,第一个想到的就是fiddler工具,说一下具体的做法: Rules -> ...
- 2014-11-3 NOIP模拟赛3
字符串 string.pas/c/cpp 1S/256MB [题目描述] 现在给一个字符串,你要做的就是当这个字符串中存在两个挨着的字符是相同的时就将这两个字符消除.需要注意的是,当把这两个字符消除后 ...
- zuul超时问题
转载:http://blog.csdn.net/tianyaleixiaowu/article/details/78772269 是这样的,今天碰到了微服务响应超时问题,而且超时时间特别短,2秒就超时 ...
- Zuul超时问题,微服务响应超时,zuul进行熔断
天碰到了微服务响应超时问题,而且超时时间特别短,2秒就超时,zuul就走熔断了. 我采用zuul作为网关,根据不同的访问路径进行微服务的路由,譬如有个服务是user,我访问user服务的某个接口时,该 ...
- HDU 6215 2017Brute Force Sorting 青岛网络赛 队列加链表模拟
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6215 题意:给你长度为n的数组,定义已经排列过的串为:相邻两项a[i],a[i+1],满足a[i]&l ...
- 怎样用Fiddler模拟网络超时
转自:http://materliu.github.io/all/web/2014/04/28/fiddler-timeout.html 用fiddler模拟网络请求超时 用fiddler模拟网络 ...
- SpringCloud之Feign 负载均衡请求超时时间
版本声明: SpringCloud:Greenwich.SR4 SpringBoot:2.1.9.RELEASE Feign调用服务的默认时长是1秒钟,也就是如果超过1秒没连接上或者超过1秒没响应,那 ...
随机推荐
- ElasticSearch安装拼音插件 elasticsearch-analysis-pinyin
elasticsearch-analysis-pinyin 是 ElasticSearch的拼音插件.强大的功能支持拼音等的搜索 1.下载源代码 源码地址https://github.com/medc ...
- SpringMvc @RequestMapping原理
讲这个之前,我们得先知道在SpringMvc启动时,会加载所有的Bean类,就是加了@Controller,@Component等组件标识的类,然后会把@RequestMapping的方法也加入到一个 ...
- XorPay 个人支付平台增加 个人支付宝支付接口
XorPay 今天新增 个人支付宝当面付 接口,欢迎大家使用. 「 XorPay 支付平台」 已经同时支持 个人微信支付接口 和 个人支付宝接口. 个人可用的 支付宝/微信支付 接口,支持 当面付 ...
- Flink--Streaming Connectors
原网址:https://ci.apache.org/projects/flink/flink-docs-release-1.7/dev/connectors/ Predefined Sources a ...
- SpringMvc redirect
SpringMVC redirect 核心 首先网上百度到的资源基本已经够用, 留作记录. SpringMVC-redirect重定向跳转传值 虽然这哥们也是转的, 但又没有留源地址. 因此 ... ...
- day3.python 学习之列表
python中列表用[ ]表示, list = [ ] #表示一个空列表 1.list = [ 'A','B','C',‘D’] print(list[0]) # 表示打印出列表中的第一个元素,列表 ...
- jQuery 获取元素当前位置offset()与position()
<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8& ...
- sparksql连接mysql
1.方法1:分别将两张表中的数据加载为DataFrame /* * 方法1:分别将两张表中的数据加载为DataFrame * */ /* Map<String,String> option ...
- mysql使用常见问题
常见问题之一: 启动mysql时显示: The server quit without updating PID file 1.可能是/usr/local/mysql/data/mysql.pid文件 ...
- service iptables xxx无效命令的情况下,如何启动/重启iptables
最近在CentOS 7.6下使用service iptables xxx相关命令,提示如下错误:The service command supports only basic LSB actions ...