HDU 1828 Picture
来源:互联网 发布:淘宝淘抢购收费标准 编辑:程序博客网 时间:2024/05/13 14:32
Problem Description
A number of rectangular posters, photographs and other pictures of the same shape are pasted on a wall. Their sides are all vertical or horizontal. Each rectangle can be partially or totally covered by the others. The length of the boundary of the union of all rectangles is called the perimeter.
Write a program to calculate the perimeter. An example with 7 rectangles is shown in Figure 1.
The corresponding boundary is the whole set of line segments drawn in Figure 2.
The vertices of all rectangles have integer coordinates.
Write a program to calculate the perimeter. An example with 7 rectangles is shown in Figure 1.
The corresponding boundary is the whole set of line segments drawn in Figure 2.
The vertices of all rectangles have integer coordinates.
Input
Your program is to read from standard input. The first line contains the number of rectangles pasted on the wall. In each of the subsequent lines, one can find the integer coordinates of the lower left vertex and the upper right vertex of each rectangle. The values of those coordinates are given as ordered pairs consisting of an x-coordinate followed by a y-coordinate.
0 <= number of rectangles < 5000
All coordinates are in the range [-10000,10000] and any existing rectangle has a positive area.
Please process to the end of file.
0 <= number of rectangles < 5000
All coordinates are in the range [-10000,10000] and any existing rectangle has a positive area.
Please process to the end of file.
Output
Your program is to write to standard output. The output must contain a single line with a non-negative integer which corresponds to the perimeter for the input rectangles.
Sample Input
7-15 0 5 10-5 8 20 2515 -4 24 140 -6 16 42 15 10 2230 10 36 2034 0 40 16
Sample Output
228矩形周长并,同矩形面积并一样用扫面线一行行统计,竖线则记录条数。
#pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio>#include<cmath>#include<map>#include<cstring>#include<algorithm>using namespace std;typedef long long LL;const int maxn = 400005;int n, m, ans, l, r;struct seg{int h, l, r;int k;bool operator <(const seg&a){return h < a.h;}}p[maxn];struct ST{int sum[maxn], dis[maxn], num[maxn], L[maxn], R[maxn];void build(int x, int l, int r){L[x] = R[x] = num[x] = sum[x] = dis[x] = 0;if (l == r) return;else{int mid = l + r >> 1;build(x + x, l, mid);build(x + x + 1, mid + 1, r);}}void get(int x, int lx, int rx){L[x] = L[lx];R[x] = R[rx];num[x] = num[lx] + num[rx];if (R[lx] && L[rx]) num[x] -= 2;dis[x] = dis[lx] + dis[rx];}void insert(int x, int l, int r, int ll, int rr, int v){if (l<ll || r >rr || sum[x] + v < 0){int mid = l + r >> 1;if (sum[x]){insert(x + x, l, mid, l, r, sum[x]);insert(x + x + 1, mid + 1, r, l, r, sum[x]);sum[x] = 0;}if (ll <= mid) insert(x + x, l, mid, ll, rr, v);if (rr > mid) insert(x + x + 1, mid + 1, r, ll, rr, v);get(x, x + x, x + x + 1);}else{sum[x] += v;if (sum[x]){L[x] = R[x] = 1;num[x] = 2;dis[x] = r - l + 1;}else if (l == r){L[x] = R[x] = 0;num[x] = 0;dis[x] = 0;}else get(x, x + x, x + x + 1);}}}st;int main(){while (scanf("%d", &n) != EOF){for (int i = 1; i <= n; i++){scanf("%d%d%d%d", &l, &p[i + i - 1].h, &r, &p[i + i].h);p[i + i - 1].l = p[i + i].l = l + 10001;p[i + i - 1].r = p[i + i].r = r + 10001;p[i + i - 1].k = -(p[i + i].k = -1);}sort(p + 1, p + n + n + 1);ans = 0;st.build(1, 1, 20000);for (int i = 1, j = st.dis[1]; i <= n + n; i++){st.insert(1, 1, 20000, p[i].l, p[i].r - 1, p[i].k);ans += abs(j - st.dis[1]) + st.num[1] * (p[i + 1].h - p[i].h);j = st.dis[1];}printf("%d\n", ans);}return 0;}
0 0
- hdu 1828 Picture
- HDU 1828 - Picture
- HDU 1828 Picture
- hdu 1828 picture
- HDU 1828 Picture
- HDU 1828 Picture
- 【49.23%】【hdu 1828】Picture
- Picture HDU 1828
- HDU 1828 Picture
- hdu 1828 Picture
- hdu 1828 picture 线段树
- hdu 1828 Picture(扫描线)
- HDU-1828-Picture(线段树)
- Picture hdu 1828 扫描线
- hdu 1828 Picture(线段树)
- |Hdu 1828|线段树|Picture
- POJ 1177 Picture & hdu 1828 Picture(扫描线)
- hdu 1828 Picture(矩形周长并)
- 银联风险水晶球项目--第三季度改造
- go 语言,统计每行短号出现的次数,且对次数进行统计
- OC循环渐进:文件管理常用操作
- Android源代码Linux Kernel下载及编译
- HTMl小知识
- HDU 1828 Picture
- 关于被安装到sdcard,无法接受到系统启动事件的问题, 修改安装路径
- android sdk 更新
- Js学习第十天----函数
- [GDOI模拟2015.08.12]囚人的旋律
- 【面试总结】百度知道后台开发实习生
- JavaScript去除字符串两边空格trim
- OC学习:OC中对文件的操作
- iOS 滤镜 和 iOS6 中的Core Image技术