HDU 1542 Atlanta (matrix coverage area of Line Segment tree)

Source: Internet
Author: User


Question: Calculate the coverage area for n matrices.

Thought: I read others' answer reports

Given the coordinates in the lower left corner of a rectangle and the coordinates in the upper right corner are respectively: (x1, y1) and (x2, y2). For such a rectangle, we construct two line segments, one positioned in x1, in the y coordinate, the range is [y1, y2], and the value of a cover domain is 1. The other line segment is located in x2, And the range is [y1, y2], given a cover value of-1. Based on this method, two line segments are constructed for each rectangle, and all line segments are sorted from left to right based on the located x.


# Include
 
  
# Include
  
   
# Include
   
    
# Include using namespace std; # define M 100 # define inf 0x3fffffff # define maxn 500000*2 struct seg {int flag; double up, down, x ;} line [M * 5]; int cmp (seg a, seg B) {return. x
    
     
= R | tree [id]. up <= l) return 0; if (tree [id]. flag) {if (tree [id]. cover> 0) // Recursion to the leaf node {double temp_x = tree [id]. x; double ans = (x-temp_x) * (tree [id]. up-tree [id]. down); tree [id]. x = x; // locate the last xtree [id]. cover + = flag; return ans;} else {tree [id]. cover + = flag; tree [id]. x = x; return 0 ;}} double ans1, ans2; ans1 = insert (id * 2, x, l, r, flag ); ans2 = insert (id * 2 + 1, x, l, r, flag); return ans1 + ans2;} int main () {int t, ca = 1; while (scanf ("% d", & t) {double x1, x2, y1, y2; int k = 0; for (int I = 0; I
     
      

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.