hdu 1754【I Hate It】
摘要:一道简单的线段树题目,好久没有刷题,偶来刷刷,除了刚开始提交RE了,原因是segtree数组开的太小了,一改大就A了,本来代码是用vim写的,用G++编译,结果老是报错,错的都很离谱,就改用code::blocks编译@_@。。。再去研究下G++。。。代码如下: 1 #include <cstdio> 2 #include <algorithm> 3 4 const int maxlen = 200000+10; 5 int scores[maxlen]; 6 7 struct node 8 { 9 int left,right; 10 int value...
阅读全文
posted @
2013-03-20 19:41
Shirlies
阅读(185)
推荐(0) 编辑
hdu 1394【Minimum Inversion Number】
摘要:线段树假如考虑iValue[i],则要先将iValue[1]->iValue[i-1]放在线段树里面,计算每一段里面包含多少个已遍历值(iValue[1]->iValue[i-1]),然后查找iValue[i]+1->n的值有多少个,这样的话,就相当与在查找iValue[1]->iValue[i-1]有多少个值是在iValue[i]+1->n范围的。(这一题目也可以用树状数组做)代码如下: 1 #include <iostream> 2 3 using namespace std; 4 5 struct node 6 { 7 int low,high;
阅读全文
posted @
2012-12-01 12:43
Shirlies
阅读(206)
推荐(0) 编辑
hdu 1264【Counting Squares】
摘要:一道线段树的题目,由于之前没怎么做过线段树的题目,这道题我觉得还是有点小难的首先将x坐标排序,然后找相邻的x坐标之间的最大y值和最小y值,这些矩形是要覆盖x,x+1坐标的,然后将yMax,yMin分散到线段树上,并用一个值标记哪些节点被分布了,最后查找一遍就可以了。代码如下: 1 #include <iostream> 2 #include <algorithm> 3 #include <cstring> 4 using namespace std; 5 6 int X_axle[20000]; 7 8 struct node 9 { 10 int xLow
阅读全文
posted @
2012-11-29 14:24
Shirlies
阅读(333)
推荐(0) 编辑