HDU 3265 Posters (segment tree scan line • Rectangular frame area and)

Source: Internet
Author: User

Test instructions Some rectangular posters to some small rectangular stickers in the specified position ask the last poster covering the area

A rectangular box can be divided into 4 separate small rectangles and then the scanning line can be used to calculate the area and

#include <cstdio> #include <algorithm>using namespace std;const int N = 100005, M = N << 2;typedef long L    Ong ll;struct sline{int x, y1, y2, flag;    Sline () {}; sline (int xx, int a, int b, int f): X (XX), Y1 (a), y2 (b), flag (f) {} bool operator< (const sline &s) Cons    t{return x < s.x;    }} line[n << 3];int len[m], cnt[m];void pushup (int p, int s, int e) {if (cnt[p]) len[p] = e-s + 1;    else if (s = = e) Len[p] = 0; else len[p] = len[p << 1] + len[p << 1 | 1];} void Update (int p, int s, int e, int l, int r, int v) {if (R < L) return;//After the split rectangle has y1 = y2 case if (l <= s &AMP;&A mp        E <= R) {Cnt[p] + = V;        Pushup (P, S, e);    Return    } int mid = (s + e) >> 1;    if (l <= mid) update (P << 1, S, Mid, L, R, v);    if (R > Mid) Update (P << 1 | 1, mid + 1, E, L, R, v); Pushup (P, S, e);}    int main () {int n, m, x1, y1, x2, y2, x3, Y3, X4, Y4, F; while (scanf ("%d", &n), n) {m = 0;            for (int i = 0; i < n; ++i) {scanf ("%d%d%d%d", &x1, &y1, &x2, &y2);            scanf ("%d%d%d%d", &x3, &y3, &x4, &y4);            Divide a rectangle into 4 rectangles line[m++] = sline (x1, y1, y2, 1);            line[m++] = sline (x3, y1, Y2,-1);            line[m++] = sline (x4, y1, y2, 1);            line[m++] = sline (x2, y1, y2,-1);            line[m++] = sline (x1, y1, y3, 1);            line[m++] = sline (x2, Y1, Y3,-1);            line[m++] = sline (x1, Y4, y2, 1);        line[m++] = sline (x2, Y4, Y2,-1);        } sort (line, line + M);        ll ans = 0;            for (int i = 0; i < m; ++i) {update (1, 1, N, Line[i].y1 + 1, line[i].y2, Line[i].flag);        Ans + = ll (len[1]) * (line[i + 1].x-line[i].x);    } printf ("%lld\n", ans); } return 0;} Last modified:2015-08-14 14:29 CST

Posters

Problem descriptionted have a new house with a huge window. In this big summer, Ted decides to decorate the window with some posters to prevent the glare outside. All things that Ted can find is rectangle posters.

However, Ted is such a picky guy, a every poster he finds something ugly. So before he pastes a poster in the window, he cuts a rectangular hole on this poster to remove the ugly part. Ted is also a careless guy so, some of the pasted posters may overlap when he pastes them on the window.

Ted wants to know the total area of the windows covered by posters. Now it's your job to figure it out.

To make your job easier, we assume the window was a rectangle located in a rectangular coordinate system. The window ' s bottom-left corner are at position (0, 0) and Top-right Corner are at position (50000, 50000). The edges of the window, the edges of the posters and the edges of the holes on the posters is all parallel with the coor Dinate axes.

Inputthe input contains several test cases. For each test case, the first line contains a single integer N (0<n<=50000), representing the total number of poster S. Each of the following N lines contains 8 integers x1, y1, x2, y2, x3, Y3, X4, Y4, showing details about one poster. (x1, y1) is the coordinates of the poster ' s Bottom-left corner, and (x2, y2) are the coordinates of the poster ' s top-right Corner. (x3, Y3) is the coordinates of the hole's Bottom-left corner, while (X4, Y4) is the coordinates of the hole ' s Top-right Co Rner. It is guaranteed that 0<=xi, yi<=50000 (I=1 ... 4) and x1<=x3<x4<=x2, Y1<=y3<y4<=y2.

The input ends with a line of single zero.

Outputfor each test case, output A, and the total area of Windows covered by posters.
Sample Input
20 0 10 10 1 1 9 92 2 8 8 3 3 7 70

Sample Output
56



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

HDU 3265 Posters (segment tree scan line • Rectangular frame area and)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.