Uva12657 Boxes in a Line】的更多相关文章

12657 - Boxes in a Line You have n boxes in a line on the table numbered 1 . . . n from left to right. Your task is to simulate 4kinds of commands:• 1 X Y : move box X to the left to Y (ignore this if X is already the left of Y )• 2 X Y : move box X…
题目链接:https://www.luogu.org/problemnew/show/UVA12657 分析: 此题使用手写链表+模拟即可.(其实可以用list,而且更简便,但是会大大的超时) 肯定是不能直接用数组模拟了,因为n,m的大小会达到100000. 然后, 1.可以编写一些辅助函数来设置链接关系. 2.注意 op==3的时候,要对xy相邻的情况进行特判,因为有这种情况 2 1 (头节点) 3 1 2 (尾节点) 3.我们会发现如果反转两次,就相当于没有翻转.如果翻转一次,op=1变为o…
题目大意 你有一行盒子,从左到右依次编号为1, 2, 3,…, n.你可以执行四种指令: 1 X Y表示把盒子X移动到盒子Y左边(如果X已经在Y的左边则忽略此指令).2 X Y表示把盒子X移动到盒子Y右边(如果X已经在Y的右边则忽略此指令).3 X Y表示交换盒子X和Y的位置.4 表示反转整条链. 盒子个数n和指令条数m(1<=n,m<=100,000) 题解 用数组来模拟链表操作,对于每个节点设置一个前驱和后继. 1操作是把x的前驱节点和x的后继节点连接,y节点的前驱和x节点连接,x节点和y…
题目大意:一个1~n的升序数字序列,有4种操作.操作1,将x放到y前面一个位置:操作2将x放到y后面的一个位置:操作3交换x和y的位置:操作4反转整个序列.求经过m次操作后的所有奇数项的和. 题目分析:建立双向链表,每次操作只需修改链表中的元素指向. 代码如下: # include<iostream> # include<cstdio> # include<cstring> # include<algorithm> using namespace std;…
题目链接:传送门 分析:每次操作都会花费大量时间,显然我们只需要关注每个元素的左边是啥,右边是啥就够了,那么用双向链表,l[i]表示i左边的数,r[i]表示i右边的数,每次操作模拟一下数组的变化就好了. 不过这样有一个问题:第4个操作似乎无法很高效地进行,如果真的按照它说的那样模拟翻转,恐怕复杂度和暴力也要差不多了,那么我们怎么处理呢? 观察发现题目只让我们输出奇数位置的编号和,也就是说,如果题目给定的序列长度就是奇数的,那么无论用多少次4操作都没有影响,否则4的次数是奇数,则用总和减去当前奇数…
 省赛B题....手写链表..其实很简单的.... 比赛时太急了,各种手残....没搞出来....要不然就有金了...注:对相邻的元素需要特判..... Problem B Boxes in a Line You have n boxes in a line on the table numbered 1~n from left to right. Your task is to simulate 4 kinds of commands: 1 X Y: move box X to the lef…
Boxes in a Line You have n boxes in a line on the table numbered 1 . . . n from left to right. Your task is to simulate 4 kinds of commands: ? 1 X Y : move box X to the left to Y (ignore this if X is already the left of Y ) ? 2 X Y : move box X to th…
  You have n boxes in a line on the table numbered 1 . . . n from left to right. Your task is to simulate 4kinds of commands: • 1 X Y : move box X to the left to Y (ignore this if X is already the left of Y ) • 2 X Y : move box X to the right to Y (i…
You have n boxes in a line on the table numbered 1 . . . n from left to right. Your task is to simulate 4 kinds of commands: • 1 X Y : move box X to the left to Y (ignore this if X is already the left of Y ) • 2 X Y : move box X to the right to Y (ig…
Boxes in a Line You have n boxes in a line on the table numbered 1 . . . n from left to right. Your task is to simulate 4 kinds of commands: • 1 X Y : move box X to the left to Y (ignore this if X is already the left of Y ) • 2 X Y : move box X to th…