HDU 1542-Atlanta

Source: Internet
Author: User

 

Question address: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1542

 

This is my first scanned line question.

 

Method: Line Segment tree + scanning line.

 

Scan the X axis to the right of the X axis.

Sort the values of X first, and convert the values of Y to vertices.

Then scanning is performed according to the ascending order of X.

Update an interval using a line segment tree, and record the total length of all intervals in the outbound state.

Multiply the total length by the span of X to obtain an area.

Add the obtained area at a time, and the final total area is the result.

 

PS:

Wa has been in existence for a long time. I checked it for more than two hours...

At last, I found that one carriage return is missing...

When it comes to adding...

I wiped it. Why didn't we return PE but wa !!!

 

# Include <iostream> # include <cstdio> # include <algorithm> # define LL (v <1) # define RR (v <1 | 1) # define tmid (L + r)> 1) Using namespace STD; const int maxn = 201; struct node {Double X, Y1, Y2; int flag; node () {} node (double A, double B, double C, int d) {x = A, Y1 = B, y2 = C, flag = D ;} bool friend operator <(node A, Node B) {return. x <B. X ;}} P [maxn]; int rec [maxn <2]; double Len [maxn <2], F [maxn]; void Update (INT l, int R, int flag, int L, Int R, int v) {If (L <= L & R <= r) Rec [v] + = flag; else {If (L <= tmid) update (L, R, flag, L, tmid, LL); If (r> tmid) Update (L, R, flag, tmid + 1, R, RR );} if (REC [v]) Len [v] = f [R + 1]-f [l]; else if (L = r) Len [v] = 0; else Len [v] = Len [ll] + Len [RR];} int tol; int Bin (Double X) {int L, R, mid; L = 0, R = tol; while (L <= r) {mid = tmid; If (F [Mid] = x) return mid; else if (F [Mid] <X) L = Mid + 1; else r = mid-1 ;}} int main () {int I, j, T = 1, n, CNT; double X1, Y1, X2, y2, sum; whi Le (~ Scanf ("% d", & N) {If (! N) break; CNT = 0; while (n --) {scanf ("% lf", & X1, & Y1, & X2, & Y2 ); P [CNT] = node (x1, Y1, Y2, 1); F [CNT ++] = Y1; P [CNT] = node (X2, Y1, Y2, -1); F [CNT ++] = Y2;} Sort (F, F + CNT); sort (p, p + CNT); For (Tol = 0, I = 1; I <CNT; I ++) if (F [I-1]! = F [I]) f [++ tol] = f [I]; memset (REC, 0, sizeof (REC); memset (Len, 0, sizeof (LEN); sum = 0; for (I = 0; I <cnt-1; I ++) {Update (Bin (P [I]. y1), Bin (P [I]. y2)-1, P [I]. flag, 0, Tol, 1); sum + = Len [1] * (p [I + 1]. x-P [I]. x);} printf ("Test Case # % d \ n", t ++); printf ("total occupied ed area: %. 2lf \ n ", sum);} return 0 ;}

 

 

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.