uva 482 - Permutation Arrays】的更多相关文章

<int, double> --> <int, string> 从而避免了输出格式: #include <vector> #include <string> #include <iostream> #include <sstream> #include <algorithm> using namespace std; int main() { ; string line1, line2; int index; str…
Description Write a program to transform the permutation 1, 2, 3,..., n according to m instructions. Each instruction (a, b) means to take out the subsequence from the a-th to the b-th element, reverse it, then append it to the end. Input There is on…
题目传送门 题意:训练指南P248 分析:逆向考虑,比如一个全排列:7345261,它也可以表示成题目中的形式,第一个数字7是由6 * (7 - 1)得到的,第二个数字3有2 * (7 - 2)得到,所以只要树状数组单点修改二分(找最远的因为有些位置是0)查询当前第s[i] + 1的数字(在BIT中指前p项和为s[i] + 1). #include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int s[N]; str…
原题链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18902 伸展树的区间翻转剪切... 如下: #include<cstdio> #include<cstdlib> #include<iostream> #include<algorithm> ; struct Node{ int v, s, rev; Node *pre, *ch[]; inline , , Node *p =…
第一棵伸展树,各种调试模板……TVT 对于 1 n 这种查询我处理的不太好,之前序列前后没有添加冗余节点,一直Runtime Error. 后来加上冗余节点之后又出了别的状况,因为多了 0 和 n+1 这两个节点,并且每次截取翻转添加到序列最后,因此无法确定 n+1 这个节点在序列的哪个位置. 比如(括号中的为添加的冗余节点): (0) 1 2 3 4 5 (6) 我把[3,4]截取翻转添加到序列尾部,会变成这样: (0)1 2 5 (6)4 3 此时我如果再希望截取[3,4],期望的结果应该是…
splay的题: 学习白书上和网上的代码敲的: #include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm> using namespace std; int n,m; struct node { node *ch[]; int s,v; int flip; node(int v):v(v) { ch[]=ch[]=NULL; s=; flip=; } void ma…
题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18902 [思路] 伸展树+打标记. 用伸展树维护这个序列,使得能够提供快速的分裂与合并O(logn),利用打标记的方法处理区间翻转的问题. 需要注意的有: 1)在splay与print中都需要合适地调用pushdown下传标记. 2)Merge操作应该满足left中所有元素都比right中的元素小,这里的大小定义为序列位置的大小而不是键值v的大小. 3)因为me…
题目意思是说  给你一个数k  然后有k个si   问你1--k 的第n个全排列是多少   注意是 1 2 3...k的全排列 不是si的 N=   由观察得知(k-i)!就是k-i个数字的全排列种数, 0=<Si<=k-i,所以显然可知如果当i==1时从第(k-1)!*s1到第n个全排列都是由第S1+1个数字開始的数列,由于每(k-1)!次排列过后,下一个排列的第1个数字都要增大1(每隔(k-1)!次,这k-1个数字都排列过一遍了,下一次仅仅能增大更前面一个,也就是第1个了) 比方对于数列{…
题意:给你k个数Si,然后给你一个等式   H= ∑  Si ∗ (K − i)!  (i=(1->k)且0 ≤ Si ≤ K − i). 叫你求出第H个全排列 其实这是一个康托展开:X=a[n]*(n-1)!+a[n-1]*(n-2)!+...+a[i]*(i-1)!+...+a[1]*0! ,其中a[i]为当前未出现的元素中是排在第几个(从0开始).这就是康托展开.我们也可以找规律解决 接着就是二分树状数组解决第S+1个未出现的位置的经典题了 #include<set> #inclu…
题目链接 题意:你的任务是根据m条指令改变排列{!,2,3,...,n}.每条指令(a,b)表示取出第a~b个元素,翻转后添加到排列的尾部.输出最终序列. 解法:splay对区间分裂合并翻转,模板题. 初学splay,代码写得有点挫,以后慢慢改~~ #include<bits/stdc++.h> using namespace std; struct Splay { ; ],siz[N],val[N],fa[N],tot,flip[N],n,m; int rel(int u) { ]==u;…