【比赛链接】:click here~~
5326 :Work
【题意】:
It’s an interesting experience to move from ICPC to work, end my college life and start a brand new journey in company.
As is known to all, every stuff in a company has a title, everyone except the boss has a direct leader, and all the relationship forms a tree. If A’s title is higher than B(A is the direct or indirect leader of B), we call it A manages B.
Now, give you the relation of a company, can you calculate how many people manage k people.
代码:
5317:RGCDQ
【题目大意】:
Mr. Hdu is interested in Greatest Common Divisor (GCD). He wants to find more and more interesting things about GCD. Today He comes up with Range Greatest Common Divisor Query (RGCDQ). What’s RGCDQ? Please let me explain it to you gradually. For a positive integer x, F(x) indicates the number of kind of prime factor of x. For example F(2)=1. F(10)=2, because 10=2*5. F(12)=2, because 12=2*2*3, there are two kinds of prime factor. For each query, we will get an interval [L, R], Hdu wants to know maxGCD(F(i),F(j)) (L≤i<j≤R)
给你 n和m,定义F(x)为的素因子种类个数,求maxGCD(F(i),F(j)) (L≤i<j≤R)
【思路】:我们发现其实F(x)的范围很小,最大:2*3*5*7*11*13*17*19>10^6,因此用sum[i][j]表示前i个数中素因子个数种类为j 的数有多少个
代码:
5323: Solve this interesting problem
【题目大意】:
给定区间[l,r],用线段树的递归建树方式build(1, n),问最小的n是多少,使得build(1,n) 中能直接建出区间[l,r]
【思路】:
从底向上搜就好了
用线段树方式建树 [ 0, n]
已知[ l, r] 结点 求n
若 建一个[0, 2*r] 的线段树 ,左子树!=右子树,[0, r] 在左子树里 则n最大为2*r
若 建一个[0, 2*r+1] 的线段树 ,左子树==右子树,[0, r] 在左子树里 这时则 [0, r] 就可以建树
搜的时候超出2*r 就直接return
注意往上dfs顺序,否则会RE!
ps:说到底,还是英文是硬伤!han!
代码: