Perimeter of multiple rectangular Edges

Source: Internet
Author: User

The world is still so impermanence, the key is to have a normal heart!

Http://www.cnblogs.com/Booble/archive/2010/10/10/1847163.html

For a detailed and patient explanation, you can understand it at a glance, and you will be fined 10 for false positives!

The code and comments for poj1177 to calculate the perimeter of multiple rectangular edges are as follows:

Tucao: Wa has been around for a long time. Why? Maxn is too small.

People's coordinates are [-]. Even if they are discretization, there should be many points.

 

Where I am prone to errors:

R> M: recursive right subtree

Maxn

Discretization
The START pointer is 1.

// Attention: // regards a line segment tree as a line segment, the significance of each vertex is to include a line segment whose unit is backward # include <iostream> # include <cstdio> # include <cstring> # include <algorithm> # include <cmath> # define lson l, m, RT <1 # define rson m + 1, R, RT <1 | 1 # define maxn 22222 using namespace STD; // indicates whether the right endpoint of the Line Segment indicated by the Left endpoint and right endpoint of the range is overwritten by bool LBD [maxn <2], RBD [maxn <2]; int Len [maxn <2]; // indicates the length covered by the node range. Int CNT [maxn <2], numseg [maxn <2]; // represents the number of lines covered by this interval, and the number of lines s from a distance. Truct seg {int L, R, H, s; seg () {} seg (int A, int B, int C, int D): l (), R (B), H (C), S (d) {} bool operator <(const seg & CMP) const {If (H = CMP. h) Return S> CMP. s; return H <CMP. h ;}} seg [maxn <1]; void push_up (int rt, int L, int R) {If (CNT [RT]) {LBD [RT] = RBD [RT] = true; Len [RT] = r-L + 1; numseg [RT] = 2;} else if (L = r) {Len [RT] = numseg [RT] = LBD [RT] = RBD [RT] = 0;} else {LBD [RT] = LBD [RT <1]; RBD [RT] = RBD [RT <1 | 1]; len [RT] = Len [RT <1] + Len [RT <1 | 1]; numseg [RT] = numseg [RT <1] + numseg [RT <1 | 1]; if (LBD [RT <1 | 1] & RBD [RT <1]) numseg [RT]-= 2 ;}} void Update (int l, int R, int C, int L, int R, int RT) {If (L <= L & R <= r) {CNT [RT] + = C; push_up (RT, l, R); return;} int M = (L + r)> 1; if (L <= m) Update (L, R, C, lson ); if (r> m) Update (L, R, C, rson); push_up (RT, L, R) ;}int main () {int n, a, B, c, d, s; int ret; while (scanf ("% d", & N )! = EOF) {S = 0; ret = 0; int lT = 1000000, rT =-100000; memset (Len, 0, sizeof (LEN); memset (numseg, 0, sizeof (numseg); memset (CNT, 0, sizeof (CNT); memset (LBD, 0, sizeof (LBD); memset (RBD, 0, sizeof (RBD); For (INT I = 0; I <n; I ++) {scanf ("% d", &, & B, & C, & D); Lt = min (LT, a); RT = max (RT, C ); // 1 indicates the bottom of the rectangle seg [s ++] = seg (A, C, B, 1); //-1 indicates the top of the rectangle. // I scanned the image from the bottom up, So I inserted the image below, delete the above Code // The CNT [RT] + = C in the update statement returns seg [s ++] = seg (a, c, d,-1 );} sort (SEG, SEG + S); // sorting ensures that int last = 0 is scanned from bottom up; seg [s]. H = 0; For (INT I = 0; I <s; I ++) {If (SEG [I]. L <seg [I]. r) // just because of the definition of the Line Segment tree, R-1 update (SEG [I] is inserted here. l, SEG [I]. r-1, SEG [I]. s, LT, RT, 1); RET + = ABS (LEN [1]-last ); // difference RET + = numseg [1] * (SEG [I + 1]. h-seg [I]. h); // Number of line segments * length of the statistical interval last = Len [1];} printf ("% d \ n", RET);} return 0 ;} int Bin (INT low, int high, double key, double X []) {While (low 

Related Article

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.