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秒没响应,那 ...
随机推荐
- 0基础浅谈反射型xss (1)
0X1:在学习xss之前,先快速学习相关的HTML代码 1. <input>标签 文本域用法: <input type="text" /> Type的作 ...
- css编写规范最佳实践
最初,在编写CSS的时候,我们往往想到哪儿就写到哪儿,它们之间的关联性和有序性并不在考虑之中.但随着代码量的增加,亦或是多人共同开发,CSS的编写规范变得重要起来了.本文通过三个方面,总结出CSS编写 ...
- css左右布局,左侧固定,右侧自适应
实现布局的几种方法,见代码: <!DOCTYPE html> <html lang="cn"> <head> <meta charset= ...
- Python:学习遇到的小问题:记事本写的脚本执行提示SystaxError:(unicode error) 'utf-8'
学习了一段时间的Python因为懒没有坚持,现在又想学,在用记事本写好py脚本运行时报错:SystaxError:(unicode error) 'utf-8' 解决的方法: 因为我的笔记本系统自带的 ...
- python学习,day3:函数式编程,*arge,**kwargs
对于不固定长度的参数,需要使用*arge,**kwargs来调用,区别是*arge是转换为元组,而kwargs转化为字典 # coding=utf-8 # Author: RyAn Bi def te ...
- (三)Audio子系统之AudioRecord.startRecording
在上一篇文章<(二)Audio子系统之new AudioRecord()>中已经介绍了Audio系统如何创建AudioRecord对象以及输入流,并创建了RecordThread线程,接下 ...
- gerapy的初步使用(管理分布式爬虫)
一.简介与安装 Gerapy 是一款分布式爬虫管理框架,支持 Python 3,基于 Scrapy.Scrapyd.Scrapyd-Client.Scrapy-Redis.Scrapyd-API.Sc ...
- Mac下安装eclipse(Mac 10.12/JDK/tomcat)
1.到官网https://www.eclipse.org/downloads/eclipse-packages/下载安装包 2.安装 注意:安装ecllipse时一定要安装JDK先,最新版本的ecli ...
- mono for android 第四课--提示框(转)
其实在VS中开发安卓代码和C#还是有一些相似性,刚开始我也不知道怎么弹出提示框,于是就百度了下,再加上个人的小聪明得到一下结果 builder.setTitle表示提示框的标题. setMessage ...
- js小技巧--摘录1
原文地址https://github.com/loverajoel/jstips 1.数组中插入元素 a.尾部追加 var arr = [1,2,3,4,5]; var arr2 = []; arr. ...