POJ Training Plan 1177_Picture (scanned line/line segment tree + discrete)

Source: Internet
Author: User

POJ Training Plan 1177_Picture (scanned line/line segment tree + discrete)

Solution report

Question:

Returns the length of the rectangle.

Ideas:

Scanned on the left.

# Include
 
  
# Include
  
   
# Include
   
    
# Include
    
     
Using namespace std; struct Seg {int lx, rx, ly, ry, h, v; friend bool operator <(Seg a, Seg B) {return a. h
     
      
R | qr
      
        > 1; update1 (rt <1, l, mid, ql, qr, v); update1 (rt <1 | 1, mid + 1, r, ql, qr, v); push_up1 (rt, l, r);} void push_up2 (int rt, int l, int r) {if (lz [rt]) {sum [rt] = _ hy [r + 1]-_ hy [l];} else sum [rt] = sum [rt <1] + sum [rt <1 | 1];} void update2 (int rt, int l, int r, int ql, int qr, int v) {if (ql> r | qr
       
         > 1; update2 (rt <1, l, mid, ql, qr, v); update2 (rt <1 | 1, mid + 1, r, ql, qr, v); push_up2 (rt, l, r);} int main () {int lx, rx, ly, ry, n, I, j; scanf ("% d ", & n); for (I = 0; I
        
         

Picture
Time Limit:2000 MS Memory Limit:10000 K
Total Submissions:10332 Accepted:5485

Description

A number of rectangular posters, photographs and other pictures of the same shape are pasted on a wall. their sides are all vertical or horizontal. each rectangle can be partially or totally covered by the others. the length of the boundary of the union of all rectangles is called the perimeter.

Write a program to calculate the perimeter. An example with 7 rectangles is shown in Figure 1.

The cZ operator? Http://www.bkjia.com/kf/ware/vc/ "target =" _ blank "class =" keylink "> memory + CjxjZW50ZXI + pgltzybzcm9" http://www.2cto.com/uploadfile/Collfiles/20140813/20140813085758254.jpg "alt =" \ ">
The vertices of all rectangles have integer coordinates.

Input

Your program is to read from standard input. the first line contains the number of rectangles pasted on the wall. in each of the subsequent lines, one can find the integer coordinates of the lower left vertex and the upper right vertex of each rectangle. the values of those coordinates are given as ordered pairs consisting of an x-coordinate followed by a y-coordinate.

0 <= number of rectangles <5000
All coordinates are in the range [-keys, 10000] and any existing rectangle has a positive area.

Output

Your program is to write to standard output. The output must contain a single line with a non-negative integer which corresponds to the perimeter for the input rectangles.

Sample Input

7-15 0 5 10-5 8 20 2515 -4 24 140 -6 16 42 15 10 2230 10 36 2034 0 40 16

Sample Output

228

Source

IOI 1998

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.