Hdu 1542 Atlanta

Source: Internet
Author: User

# Include <iostream> # include <cstdio> # include <algorithm> # define MAXN 2222 using namespace std; struct line {double s, e, h, type; // records the starting and ending points of each line from the area of X weeks} L [MAXN]; // whether the bottom or the bottom is 1 High yes-1 means that the bottom is covered. High is to delete the double tree [MAXN <2]; int cnt [MAXN <2]; double X [MAXN <2]; bool cmp (line a, line B) {return. h <B. h; // sort by line height} void pushup (int num, int l, int r) {if (cnt [num]) tree [num] = X [r + 1]-X [l]; // if completely overwritten, // else if (l = r) tree [num] = 0; else tree [num] = tree [num <1] + tree [num <1 | 1]; // if not completely overwritten} int bin (double tag, int top) // returns the position of the discretization binary query {int bo = 0; int to = top-1; int mid; while (bo <=) {mid = (bo + to)> 1; if (X [mid] = tag) r Eturn mid; else if (X [mid]> tag) to = mid-1; else bo = mid + 1;} return-1;} void update (int num, int s, int e, int l, int r, int val) {if (l <= s & r> = e) {cnt [num] + = val; pushup (num, s, e); // if you don't want this sentence, the node will not be updated with return;} int mid = (s + e)> 1; if (l <= mid) update (num <1, s, mid, l, r, val); if (r> mid) update (num <1 | 1, mid + 1, e, l, r, val); pushup (num, s, e);} int main () {int n; int cas = 1; while (scanf ("% d", & n )! = EOF & n) {int m = 0; while (n --) {double a, B, c, d; scanf ("% lf ", & a, & B, & c, & d); // discretization X [m] = a; L [m]. s = a; L [m]. e = c; L [m]. h = B; L [m ++]. type = 1; X [m] = c; L [m]. s = a; L [m]. e = c; L [m]. h = d; L [m ++]. type =-1;} sort (L, L + m, cmp); sort (X, X + m); int k = 1; for (int I = 1; I <m; I ++) {if (X [I]! = X [I-1]) X [k ++] = X [I];} memset (tree, 0, sizeof (tree); memset (cnt, 0, sizeof (cnt); double ans = 0; for (int I = 0; I <m-1; I ++) {int lef = bin (L [I]. s, k); int rig = bin (L [I]. e, k)-1; if (lef <= rig) update (1, 0, k, lef, rig, L [I]. type); ans + = tree [1] * (L [I + 1]. h-L [I]. h);} printf ("Test case # % d \ nTotal received area: %. 2lf \ n ", cas ++, ans );}}

 

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.