线段树
Joyyiwei
这个作者很懒,什么都没留下…
展开
-
UVA - 11732 strcmp() Anyone?
题意:题目给出了标准strcmp()函数的代码,给你n个单词(n 思路:字符串S1,S2比较分两种情况:S1和S2有相同的前缀S,那么ans = len(S)*2+1;S1和S2完全相同的话:ans = (len(S)+1) * 2,等于算上了‘\0’然后按照Trie的构造方法:采用了左儿子右兄弟的方法,但是看到网上的都是提交错误,就先存着#include #include #i原创 2014-02-20 22:54:19 · 1165 阅读 · 0 评论 -
HDU - 1394 Minimum Inversion Number (线段树求逆序数)
DescriptionThe inversion number of a given number sequence a1, a2, ..., an is the number of pairs (ai, aj) that satisfy i aj.For a given sequence of numbers a1, a2, ..., an, if we move the原创 2014-07-31 10:20:02 · 785 阅读 · 0 评论 -
HDU - 2795 Billboard
DescriptionAt the entrance to the university, there is a huge rectangular billboard of size h*w (h is its height and w is its width). The board is the place where all possible announcements are po原创 2014-08-01 10:02:11 · 801 阅读 · 0 评论 -
HDU - 4902 Nice boat
DescriptionThere is an old country and the king fell in love with a devil. The devil always asks the king to do some crazy things. Although the king used to be wise and beloved by his people. Now原创 2014-07-31 21:25:51 · 943 阅读 · 0 评论 -
HDU - 1698 Just a Hook (线段树区间修改)
DescriptionIn the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of the heroes. The hook is made up of several consecutive metallic sticks which are of the same lengt原创 2014-08-03 09:33:24 · 980 阅读 · 0 评论 -
POJ - 3468 A Simple Problem with Integers (区间求和)
DescriptionYou have N integers, A1, A2, ... ,AN. You need to deal with two kinds of operations. One type of operation is to add some given number to each number in a given interval. The other原创 2014-08-03 10:25:45 · 785 阅读 · 0 评论 -
UVA - 11983 Weird Advertisement (线段树求并面积)
DescriptionGWeird AdvertisementRenat Mullakhanov (rem), one of the most talented programmers in the world, passed away on March 11, 2011. This is very sad news for al原创 2014-08-11 19:54:00 · 861 阅读 · 0 评论 -
POJ - 2528 Mayor's posters (线段树+离散化)
DescriptionThe citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral posters at all places at their whim. The city counci原创 2014-08-03 14:45:14 · 902 阅读 · 0 评论 -
HDU - 5023 A Corrupt Mayor's Performance Art(区间修改)
Problem DescriptionCorrupt governors always find ways to get dirty money. Paint something, then sell the worthless painting at a high price to someone who wants to bribe him/her on an auction, this原创 2014-09-20 20:38:05 · 1039 阅读 · 0 评论 -
UVA - 11402 Ahoy, Pirates! (线段树)
In the ancient pirate ages, the Pirate Land was divided into two teams ofpirates, namely, the Buccaneer and the Barbary pirates.Each pirate’s team was not fixed, sometimes the opponent pirates attacke原创 2014-09-11 23:12:02 · 1686 阅读 · 0 评论 -
SGU - 311 Ice-cream Tycoon(线段树)
DescriptionYou've recently started an ice-cream business in a local school. During a day you have many suppliers delivering the ice-cream for you, and many students buying it from you. You are原创 2014-10-20 00:05:52 · 1366 阅读 · 0 评论 -
POJ - 2991 Crane (线段树+计算几何)
DescriptionACM has bought a new crane (crane -- jeřáb) . The crane consists of n segments of various lengths, connected by flexible joints. The end of the i-th segment is joined to the beginning o原创 2014-08-04 15:41:14 · 1456 阅读 · 0 评论 -
POJ - 3225 Help with Intervals (开闭区间)
DescriptionLogLoader, Inc. is a company specialized in providing products for analyzing logs. While Ikki is working on graduation design, he is also engaged in an internship at LogLoader. Among原创 2014-08-03 20:33:24 · 965 阅读 · 0 评论 -
POJ - 1436 Horizontally Visible Segments
DescriptionThere is a number of disjoint vertical line segments in the plane. We say that two segments are horizontally visible if they can be connected by a horizontal line segment that does not原创 2014-08-03 23:06:52 · 1122 阅读 · 0 评论 -
UVA - 12299 RMQ with Shifts (线段树:单点修改,区间查询)
题意:在传统的RMQ的基础上加上一个操作:shift(i1,i2,i3...ik),表示将这些元素,依次向左移动一位思路:在原先线段树的基础上再加上:首先要先得到该位的数字,那么就是在[i,i]的区间找最小值,然后将该位置的值修改为后一位#include #include #include #include using namespace std;const int MAXN =原创 2014-02-24 19:30:40 · 963 阅读 · 0 评论 -
HDU - 1166 敌兵布阵
题意:省略思路:经典的线段树更新节点#include #include #include #include using namespace std;const int N = 10;const int MAXN = 50010;struct Node{ int left,right; int sum;}node[MAXN*4];int n,num[MAX原创 2014-02-19 22:27:27 · 908 阅读 · 0 评论 -
HDU - 1754 I Hate It
题意:中文题,思路:线段树的节点更新,储存区间的最大值#include #include #include #include using namespace std;const int MAXN = 20010;int tree[MAXN<<1+10];void build_tree(int l,int r,int root){ if (l == r){原创 2014-03-05 17:00:48 · 759 阅读 · 0 评论 -
HDU - 1542 Atlantis (线段树)
题意:给出每个矩形的左下角,右上角,求所有矩形的并面积,就是不重复计算重复的部分思路:线段树的一个应用,还是太年轻,看了别人的方法点击打开链接#include #include #include #include using namespace std;const int MAXN = 110;struct Line{ double x,y_down,y_up; int原创 2014-04-16 21:39:58 · 723 阅读 · 0 评论 -
UVA - 11525 Permutation
题意:求1-k的排列中第n大的序列,题目给出n的计算方法: n = si*(k-1)+s2*(k-2)...+sk*0!; 并给你s1-sk思路:首先我们明确,比如321是集合{1,2,3}的第几大的序列,从第一位开始3开头的话,那么显然这个序列的前面就一定会有1,2开头的学列,就是2*2!,依次类推我们就可以确定这个学列是第几大的了,但是要注意到原创 2014-05-03 21:05:30 · 920 阅读 · 0 评论 -
HDU - 2688 Rotate
题意:很容易理解,求每次序列的顺序数思路:要用到线段数,不然会超时,第一次处理的时候,用线段树每次来查询树的相对的位置的前几个的个数,之后交换的时候,判断用第一个交换数的大小就可以计算个数了 ,注意输出,用cout过的#include #include #include #include using namespace std;const int MAXN = 3000005;原创 2014-04-01 22:20:54 · 943 阅读 · 0 评论 -
UVALive - 4108 SKYLINE (线段树的区间修改)
题意:求覆盖的长度,覆盖的要求是该线段最高思路:线段树的区间修改,每次都插入一条线段,如果该线段覆盖的区间的最高值小于插入的线段,那么计算长度的时候遇到一条线段被分开会很麻烦,需要rp--#include #include #include #include using namespace std;#define lson (rt<<1)#define rson (rt<<1|原创 2014-05-06 18:10:00 · 1228 阅读 · 0 评论 -
HDU - 1828 Picture (线段树求并周长)
题意:求原创 2014-04-21 18:15:12 · 668 阅读 · 0 评论 -
POJ - 2828 Buy Tickets (线段树单点更新)
DescriptionRailway tickets were difficult to buy around the Lunar New Year in China, so we must get up early and join a long queue…The Lunar New Year was approaching, but unluckily the Little原创 2014-08-01 11:36:59 · 846 阅读 · 0 评论 -
POJ - 2886 Who Gets the Most Candies? (反素数+线段树)
DescriptionN children are sitting in a circle to play a game.The children are numbered from 1 to N in clockwise order. Each of them has a card with a non-zero integer on it in his/her hand. Th原创 2014-08-02 13:21:10 · 948 阅读 · 0 评论 -
HDU Hilarity (dfs序+线段树)
Problem DescriptionAfter June 1st, elementary students of Ted Land are still celebrating "The Sacred Day of Elementary Students”. They go to the streets and do some elementary students stuff. So w原创 2014-10-31 16:23:22 · 1295 阅读 · 0 评论