用树链剖分求LCA的模板: 1 #include<iostream> 2 #include<algorithm> 3 using namespace std; 4 const int maxn=40005; 5 int n,m; 6 int head[maxn],to[maxn<<1],w[maxn<<1],nxt[maxn<<1],tot; 7 int fa[maxn],dep[maxn],son[maxn],top[maxn],size[ma…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1394 Minimum Inversion Number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 10…
The k-th Largest Group Time Limit: 2000MS Memory Limit: 131072K Total Submissions: 8807 Accepted: 2875 Description Newman likes playing with cats. He possesses lots of cats in his home. Because the number of cats is really huge, Newman wants to g…
Data Structure? Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem Description Data structure is one of the basic skills for Computer Science students, which is a particular way of storing and organizing data…
The k-th Largest Group Time Limit: 2000MS Memory Limit: 131072K Total Submissions: 8353 Accepted: 2712 Description Newman likes playing with cats. He possesses lots of cats in his home. Because the number of cats is really huge, Newman wants to g…
题目链接:http://poj.org/problem?id=2299 Description In this problem, you have to analyze a particular sorting algorithm. The algorithm processes a sequence of n distinct integers by swapping two adjacent sequence elements until the sequence is sorted in…
Ultra-QuickSort 题目链接:http://poj.org/problem?id=2299 Time Limit: 7000MS Memory Limit: 65536K Total Submissions: 51641 Accepted: 18948 Description In this problem, you have to analyze a particular sorting algorithm. The algorithm processes a sequen…
+二分法求平方根 x = float(raw_input('Enter the number')) low = 0 high = x guess = (low + high ) / 2 if x < 0: print 'Number Error' while abs(guess**2 - x) > 1e-5: if guess**2 < x: low = guess else: high = guess guess = (low + high) / 2 print 'The root o…
[NOIP2013提高&洛谷P1966]火柴排队 Description 涵涵有两盒火柴,每盒装有 n 根火柴,每根火柴都有一个高度. 现在将每盒中的火柴各自排成一列, 同一列火柴的高度互不相同, 两列火柴之间的距离定义为: ∑(ai-bi)^2 其中 ai 表示第一列火柴中第 i 个火柴的高度,bi 表示第二列火柴中第 i 个火柴的高度. 每列火柴中相邻两根火柴的位置都可以交换,请你通过交换使得两列火柴之间的距离最小.请问得到这个最小的距离,最少需要交换多少次?如果这个数字太大,请输出这个最小…
/* Horner */ /*多项式:A(x)=a[n]X^n+a[n-1]x^n-1+...+a[1]X^1+a[0]X^0*/ #include <stdio.h> long int horner(int coefficient[], int n, int x) /*coefficient[]为待求多项式的系数数组,n为数组大小,x为多项式中未知数x的具体值*/ { /*注意:coefficient[0]存放系数a0,coefficient[1]存放系数a1,以此类推*/ int i; l…
用二分法求在(a,b)上单调的函数近似值 第八行的表达式可更改,第三行的kexi决定的精度,小数值计算可将第五行的extended更为real或double PROGRAM EQUANTION (input,output); CONST kexi=0.0000001; VAR a,b,c:extended; FUNCTION fx(x:extended):extended; BEGIN fx:=ln(x)/ln(2); END; BEGIN writeln('Please input a a…
题目链接 Sequence II Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 331 Accepted Submission(s): 151 Problem Description Long long ago, there is a sequence A with length n. All numbers in this se…
题是水题,学习一下用树状数组求LIS. 先离散化一下,注意去重:然后就把a[i]作为下标,dp[i]作为值,max作为维护的运算插进树状数组即可. 如果是上升子序列,询问(a[i] - 1):如果是不下降子序列,询问(a[i]). ; int n, m, a[maxn], b[maxn], dp[maxn], f[maxn]; void Modify(int x, int val) { for (; x <= m; x += x&-x) f[x] = max(f[x], val); } in…