2012ACM-ICPC杭州站A题

题目http://acm.hdu.edu.cn/showproblem.php?pid=4453

Looploop

 

题意:

有个循环链表,一个指针。

然后又几个操作

1: add x 
Starting from the arrow pointed element, add x to the number on the clockwise first k2 elements.
从当前指针顺时针查k2个数,这k2个数全部加x

 



2: reverse
Starting from the arrow pointed element, reverse the first k1 clockwise elements.

从当前指针顺时针查k1个数,这k1个数翻转

 



3: insert x 
Insert a new element with number x to the right (along clockwise) of the arrow pointed element.
在指针之后插入一个数x



4: delete 
Delete the element the arrow pointed and then move the arrow to the right element.
删除指针所指的数,指针指向顺时针的下一个

 



5: move x 
x can only be 1 or 2. If x = 1 , move the arrow to the left(along the counterclockwise) element, if x = 2 move the arrow to the right element.
指针移动

x=1时逆时针移动一个位置

x=2时指针顺时针移动一个位置



6: query
Output the number on the arrow pointed element in one line.
询问当前指针所指的值

 

 

其实这道题很水的,如果想到一个数据结构的话---dequeue

当时我虽然想到了,可是当时感冒了,头很晕,或者其他原因吧,这道题被队长放弃了。

结束比赛后我一想这么水。

现在题挂出来了就编出来了。

 

思路:三个deque,一个方向标记,一个延迟标记。

第一个deque存0至k1个数,方向标记为正

第二个deque存k1至k2个数

第三个deque存剩下的

可以参考这个图

说到这如果熟悉deque的话就应该明白了

详细见代码吧

 

View Code
  1 #include<iostream>
  2 #include<cstdio>
  3 #include<queue>
  4 using namespace std;
  5 struct Root{
  6     deque<int>que1,que2,que3;
  7     int _add;
  8     bool head;
  9     
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值