Description
There is several ancient Greek texts that contain descriptions of the fabled island Atlantis. Some of these texts even include maps of parts of the island. But unfortunately, these maps describe different regions of Atlantis. Your friend Bill has to know the total area for which maps exist. You (unwisely) volunteered to the write a program that calculates this quantity.
Input
The input file consists of several test cases. Each test case is starts with a line containing a single integer n (1<=n<=100) of available maps. The n following lines describe one map each. Each of the these lines contains four numbers x1;y1;x2;y2 (0<=x1<x2<=100000;0<=y1<y2<=100000), not necessarily integers. The values (x1; y1) and (x2;y2) is the coordinates of the Top-left resp. Bottom-right corner of the mapped area.
The input file is terminated by a line containing a single 0. Don ' t process it.
Output
For each test case, the your program should the output one section. The first line of all sections must be ' test Case #k ', where k is the number of the the ' Test case ' (starting with 1). The second one must be ' total explored area:a ', where A is the ' total explored area ' i.e. the area of the the Union of all Rec Tangles in this test case), printed exact to both digits to the right of the decimal point.
Output a blank line after each test case.
Sample Input
2 10 10 20 20 15 15 25 25.5 0
Sample Output
Test case #1 Total explored area:180.00
1#include <cstdio>2#include <cstring>3#include <algorithm>4 using namespacestd;5 structP16 {7 DoubleX,y1,y2;8 intv;9};p 1 str[ .];Ten BOOLCOM (P1 a,p1 b) One { A returna.x<b.x; - } - Doubley[ .]; the structP2 - { - intl,r,c; - DoubleS,LL,RR; +};p 2 tree[4100]; - voidBuildintLintRintp) + { ATree[p].l=l;tree[p].r=R; attree[p].s=0; -Tree[p].c=0; -Tree[p].ll=Y[l]; -Tree[p].rr=Y[r]; - if(L +1==R)return ; - intM= (L+R)/2; inBuild (l,m,p*2); -Build (m,r,p*2+1); to } + voidPushup (intp) - { the if(tree[p].c>0) * { $tree[p].s=tree[p].rr-Tree[p].ll;Panax Notoginseng return ; - } the if(tree[p].l+1==TREE[P].R) tree[p].s=0; + Elsetree[p].s=tree[p*2].s+tree[p*2+1].s; A } the voidUnintp,p1 e) + { - if(e.y1==tree[p].ll&&e.y2==TREE[P].RR) $ { $tree[p].c+=e.v; - pushup (p); - return ; the } - if(e.y2<=tree[p*2].RR) un (p*2, e);Wuyi Else if(e.y1>=tree[p*2+1].LL) un (p*2+1, e); the Else - { WuP1 ee=e; -ee.y2=tree[p*2].RR; AboutUn (p*2, EE); $Ee=e; -ee.y1=tree[p*2+1].ll; -Un (p*2+1, EE); - } A pushup (p); + } the intMain () - { $ intn,i,j,k=1, T; the DoubleX1,x2,y1,y2,ans; the while(~SCANF ("%d",&N)) the { thet=1; - if(n==0) Break; in for(i=1; i<=n;i++) the { thescanf"%LF%LF%LF%LF",&x1,&y1,&x2,&y2); Aboutstr[t].x=X1; thestr[t].y1=Y1; theStr[t].y2=Y2; thestr[t].v=1; +y[t]=Y1; -t++; thestr[t].x=x2;Bayistr[t].y1=Y1; theStr[t].y2=Y2; thestr[t].v=-1; -y[t]=Y2; -t++; the } theSort (str+1, str+t,com); theSort (y+1, y+t); theBuild1, T1,1); -ans=0.0; theUn1, str[1]); the for(i=2; i<t;i++) the {94ans+=tree[1].s* (str[i].x-str[i-1].x); theUn1, Str[i]); the } theprintf"Test Case #%d\n", k);98printf"Total explored area:%.2lf\n\n", ans); Aboutk++; - }101}
POJ 1151 Atlantis (segment tree + scan line)