It is a bit difficult for a line segment tree with an area covered by hdu of 1255 to calculate the intersection of the area ~~ Write this type for the first time
Covered AreaTime Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission (s): 3968 Accepted Submission (s): 1967
Problem Description is a number of rectangles on the plane. The area of the area covered by these rectangles is obtained at least twice.
The first line of Input data is a positive integer T (1 <= T <= 100), representing the number of test data. the first row of each test data is a positive integer N (1 <= N <= 1000), representing the number of rectangles, followed by N rows of data, each row contains four floating point numbers, it indicates the coordinates of the upper left corner and lower right corner of a rectangle on the plane. The upper and lower sides of the rectangle are parallel to the X axis, and the left and right sides are parallel to the Y axis. the coordinate ranges from 0 to 100000.
Note: This question contains a large amount of input data. We recommend that you use scanf to read data.
Output for each group of test data, calculate the area of the area covered by these rectangles at least twice. The result is retained with two decimal places.
Sample Input
251 1 4 21 3 3 72 1.5 5 4.53.5 1.25 7.5 46 3 10 730 0 1 11 0 2 12 0 3 1
Sample Output
7.630.00
Blog now ~~ I cannot explain it ~ Http://www.cnblogs.com/ka200812/archive/2011/11/13/2247064.html
Code:
#include
#include using namespace std ;double y[2010] ;struct Line{double x,y_up,y_down ;int mark;}line[2010];struct node{double x;double y_up,y_down;double cover;bool isLeaf ;}st[400100];void build(int l , int r , int pos){st[pos].x = -1 ;st[pos].y_down = y[l] ;st[pos].y_up = y[r] ;st[pos].cover = 0 ;st[pos].isLeaf = false ;if(l+1 == r){st[pos].isLeaf = true ;return ;}int mid = (l+r)>>1 ;build(l,mid,pos<<1) ;build(mid,r,pos<<1|1) ;}double insert(double x , double y_down , double y_up , int mark , int pos){if(st[pos].y_down>=y_up || st[pos].y_up<=y_down){return 0 ;}if(st[pos].isLeaf){if(st[pos].cover>1){double tempx = st[pos].x ;double area = (x-tempx)*(st[pos].y_up-st[pos].y_down) ;st[pos].x = x ;st[pos].cover += mark ;return area ;}else{st[pos].cover += mark ;st[pos].x = x ;return 0 ;}}return insert(x,y_down,y_up,mark,pos<<1)+insert(x,y_down,y_up,mark,pos<<1|1) ;}bool cmp(const Line &a , const Line &b){return a.x