HUD 1542 -- Atlanta HDU

Source: Internet
Author: User

Scanning line problems

The first scanning line was followed by other people's code.

The tree does not have much content, so it is not put into the structure.

Map ing is very convenient and inefficient.

// 0 Ms 368 K g ++ # include <map> # include <iostream> # include <cstdio> # include <cstring> # include <algorithm> using namespace STD; # define maxn 205 # define mid (L + r)> 1) # define ls (RT <1) # define RS (RT <1 | 1) struct line {double L, R; double H; int flag; line () {} line (double A, double B, double C, int D): l (), R (B), H (C), flag (d) {}} A [maxn <1]; Double X [maxn <1]; // The X-axis int cover [maxn <2] from the left start point of the interval; // The number of times the entire interval is overwritten. If not, the value 0 double is assigned. Sum [maxn <2]; // The overwrite length of int CNT, K; bool CMP (const line & A, const line & B) {return. h <B. h;} void pushup (int l, int R, int RT) {If (cover [RT]) sum [RT] = x [R + 1]-X [l]; else if (L = r) sum [RT] = 0; else sum [RT] = sum [ls] + sum [RS];} void change (int c, int L, int R, int L, int R, int RT) {If (L = L & R = r) {cover [RT] + = C; pushup (L, R, RT); return;} If (r <= mid) Change (C, L, R, L, mid, ls ); else if (L> mid) Change (C, L, R, Mid + 1, R, RS); Else {change (C, L, mid, L, mid, ls); change (C, Mid + 1, R, Mid + 1, R, RS );} pushup (L, R, RT) ;}int main () {int N; double x1, x2, Y1, Y2; int c = 1; while (~ Scanf ("% d", & N), n) {CNT = 0; k = 0; Map <double, int> m; For (INT I = 0; I <n; I ++) {scanf ("% lf", & X1, & Y1, & X2, & Y2 ); A [CNT ++] = line (x1, x2, Y1, 1); A [CNT ++] = line (x1, x2, Y2,-1 ); if (M [X1] = 0) m [X1] = ++ K; If (M [X2] = 0) m [X2] = ++ K ;} map <double, int>: iterator ITER; k = 0; For (iter = m. begin (); iter! = M. end (); ITER ++) {x [++ K] = ITER-> first; ITER-> second = K;} // build (1, 1, k ); memset (sum, 0, sizeof (SUM); memset (cover, 0, sizeof (cover); sort (A, A + CNT, CMP); double ans = 0.0; for (INT I = 0; I <cnt-1; I ++) {int L = m [A [I]. l]; // refers to the interval number int r = m [A [I] starting from this point. r]-1; // The interval label on the right should be-1 Change (A [I]. flag, L, R, 1, K-1, 1); ans + = sum [1] * (a [I + 1]. h-A [I]. h);} printf ("Test Case # % d \ ntotal received area: %. 2f \ n ", C ++, ANS);} 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.