个人心得:线段树就是将一段序列拆分为一个个单独的节点,不过每俩个节点又可以联系在一起,所以就能很好的结合,比如这一题, 每次插入的时候都将这一段区间的最大最小值更新,就能大大减少时间. 这个线段树建立是以数组的,根节点为0,后面每次都是父节点*2+1/2. 这题简单的教会了我如何创建线段树,以及一些简单的线段树操作,还要继续加深. For the daily milking, Farmer John's N cows (1 ≤ N ≤ 50,000) always line up in the…
线段树 Description N (2 <= N <= 8,000) cows have unique brands in the range 1..N. In a spectacular display of poor judgment, they visited the neighborhood 'watering hole' and drank a few too many beers before dinner. When it was time to line up for the…
Cows 题目:http://poj.org/problem?id=2481 题意:有N头牛,每仅仅牛有一个值[S,E],假设对于牛i和牛j来说,它们的值满足以下的条件则证明牛i比牛j强壮:Si <=Sjand Ej <= Ei and Ei - Si > Ej - Sj. 如今已知每一头牛的測验值,要求输出每头牛有几头牛比其强壮. 思路:将牛依照S从小到大排序.S同样依照E从大到小排序,这就保证了排在后面的牛一定不比前面的牛强壮. 再依照E值(离散化后)建立一颗线段树(这里最值仅仅有1…
Let the light guide us Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 62768/32768 K (Java/Others) Total Submission(s): 677 Accepted Submission(s): 226 Problem Description Plain of despair was once an ancient battlefield where those brave…
Lost Cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10354 Accepted: 6631 Description N (2 <= N <= 8,000) cows have unique brands in the range 1..N. In a spectacular display of poor judgment, they visited the neighborhood 'watering h…