随笔分类 -  线段树

摘要:HDU 1542 传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1542题目大意就是几个矩形相交,然后求出总的覆盖面积,覆盖多次的按一次算。典型的面积并问题。大体思路: 记录所给的点,排序,去掉重复的点,对点编号,可以理解成存放点的数组的下表即为编号。 对Y轴建立线段树,利用线段树计算面积。 AC_code: 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #include <iostream> 5 #include 阅读全文
posted @ 2013-06-04 21:24 好小孩 阅读(183) 评论(0) 推荐(0)
摘要:题意就是给你多个矩形,然后算出这些矩形所框出来的总面积,框过多次的按一次算。 但是题目给的是二维的,线段树只是解决一维的问题比较简单。题目数据范围为0~100,所以我就建了一百棵线段树,这样就可以转化成一维的问题来解决了。-_-|| 结果跑了70+ms 不知道还能再怎么优化……HDU里面有好多0ms的大神…… 1 #include <cstdio> 2 #include <cstring> 3 4 int st[110][10100]; 5 6 int change(int *t,int ml,int mr,int node,int l,int r) 7 { if(t[ 阅读全文
posted @ 2013-05-31 21:34 好小孩 阅读(181) 评论(3) 推荐(0)
摘要:1 #include <cstdio>//大白书上说节点数最多有2*n-1个 n为区间长度 2 #include <cstring>//这个题开420000的数组却RE了 换成100W+就过了……sad 3 #include <cstdlib> 4 #include <algorithm> 5 #include <iostream> 6 7 8 using namespace std; 9 10 int st[1048576]; 11 int gr[210000]; 12 13 int max(int x,int y) 14 { 15 阅读全文
posted @ 2013-05-29 21:33 好小孩 阅读(207) 评论(5) 推荐(0)
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1166用结构体做的 470+ms; 1 #include <cstdio> 2 #include <algorithm> 3 #include <iostream> 4 #include <cstdlib> 5 #include <queue> 6 #include <cmath> 7 #include <cstring> 8 9 using namespace std; 10 11 struct N 12 { 13 阅读全文
posted @ 2013-05-29 16:24 好小孩 阅读(152) 评论(0) 推荐(0)