题目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的话就应该明白了
详细见代码吧
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