HDU1377_Counting Squares (scanned line/line segment tree)

Source: Internet
Author: User

HDU1377_Counting Squares (scanned line/line segment tree)

Solution report

Question:

Rectangular area and.

Ideas:

Scanned line + line segment tree

# Include
 
  
# Include
  
   
# Include
   
    
Using namespace std; struct Seg {int lx, rx, h, v; friend bool operator <(Seg a, Seg B) {return a. h
    
     
R | qr
     
      
> 1; update (rt <1, l, mid, ql, qr, v); update (rt <1 | 1, mid + 1, r, ql, qr, v); push_up (rt, l, r);} int main () {int n, I, j, x1, y1, x2, y2, x3, y3, x4, y4; while (~ Scanf ("% d", & x1, & y1, & x2, & y2) {int m = 0; if (x1 = y1 & x2 = y2 & x1 = x2 & x1 =-2) break; memset (lz, 0, sizeof (lz )); memset (sum, 0, sizeof (sum); seg [m]. lx = min (x1, x2); seg [m]. rx = max (x1, x2); seg [m]. v = 1; seg [m ++]. h = min (y1, y2); seg [m]. lx = min (x1, x2); seg [m]. rx = max (x1, x2); seg [m]. v =-1; seg [m ++]. h = max (y1, y2); while (~ Scanf ("% d", & x1, & y1, & x2, & y2 )) {if (x1 = y1 & x2 = y2 & x1 = x2 & x1 =-2) break; if (x1 = y1 & x2 = y2 & x1 = x2 & x1 =-1) break; seg [m]. lx = min (x1, x2); seg [m]. rx = max (x1, x2); seg [m]. v = 1; seg [m ++]. h = min (y1, y2); seg [m]. lx = min (x1, x2); seg [m]. rx = max (x1, x2); seg [m]. v =-1; seg [m ++]. h = max (y1, y2);} sort (seg, seg + m); int ans = 0; for (I = 0; I
      
       

Counting Squares Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission (s): 1318 Accepted Submission (s): 671


Problem DescriptionYour input is a series of rectangles, one per line. each rectangle is specified as two points (X, Y) that specify the opposite corners of a rectangle. all coordinates will be integers in the range 0 to 100. for example, the line
5 8 7 10
Specifies the rectangle who's corners are (5, 8), (7, 8), (7, 10), (5, 10 ).
If drawn on graph paper, that rectangle wocould cover four squares. your job is to count the number of unit (I. e ., 1*1) squares that are covered by any one of the rectangles given as input. any square covered by more than one rectangle shoshould only be counted once.

InputThe input format is a series of lines, each containing 4 integers. four-1's are used to separate problems, and four-2's are used to end the last problem. otherwise, the numbers are the x-ycoordinates of two points that are opposite corners of a rectangle.

OutputYour output shocould be the number of squares covered by each set of rectangles. Each number shocould be printed on a separate line.

Sample Input
5 8 7 106 9 7 86 8 8 11-1 -1 -1 -10 0 100 10050 75 12 9039 42 57 73-2 -2 -2 -2

Sample Output
810000

Source Zhejiang University of Technology's fourth college Program Design Competition

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.