Atlantis
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 9214 Accepted Submission(s): 3934
Problem Description
There are 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 write a program that calculates this quantity.
Input
The input file consists of several test cases. Each test case 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 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) are 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.
The input file is terminated by a line containing a single 0. Don’t process it.
Output
For each test case, your program should output one section. The first line of each section must be “Test case #k”, where k is the number of 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 union of all rectangles in this test case), printed exact to two digits to the right of the decimal point.
Output a blank line after each test case.
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
Source
Recommend
好吧,还是面积并,哈数居然是关键字,ce一次
ac代码
Problem: 1151 User: kxh1995
Memory: 180K Time: 16MS
Language: C++ Result: Accepted
Source Code
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct s
{
double x1,x2,y;
int flag;
}a[880];
double __hash[805],sum[805];
int col[805];
int cmp(s a,s b)
{
return a.y<b.y;
}
int bseach(double key,int n)
{
int l=1,r=n;
while(l<=r)
{
int mid=(l+r)>>1;
if(__hash[mid]==key)
return mid;
if(__hash[mid]<key)
l=mid+1;
else
r=mid-1;
}
return l;
}
void pushup(int tr,int l,int r)
{
if(col[tr])
sum[tr]=__hash[r+1]-__hash[l];
else
if(l==r)
sum[tr]=0;
else
sum[tr]=sum[tr<<1]+sum[tr<<1|1];
}
void update(int L,int R,int l,int r,int tr,int flag)
{
if(L<=l&&r<=R)
{
col[tr]+=flag;
pushup(tr,l,r);
return;
}
int mid=(l+r)>>1;
if(L<=mid)
update(L,R,l,mid,tr<<1,flag);
if(R>mid)
update(L,R,mid+1,r,tr<<1|1,flag);
pushup(tr,l,r);
}
int main()
{
int n,c=0;
while(scanf("%d",&n)!=EOF)
{
if(n==0)
break;
memset(col,0,sizeof(col));
memset(sum,0,sizeof(sum));
double x1,x2,y1,y2;
int i,k=1;
for(i=1;i<=n;i++)
{
scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
a[k].x1=x1;
a[k].x2=x2;
a[k].y=y1;
a[k].flag=1;
__hash[k++]=x1;
a[k].x1=x1;
a[k].x2=x2;
a[k].y=y2;
a[k].flag=-1;
__hash[k++]=x2;
}
sort(a+1,a+k,cmp);
//int cnt=unique(hash+1,hash+k)-(hash+1);
sort(__hash+1,__hash+k);
double ans=0;
for(i=1;i<k-1;i++)
{
int x,y;
x=bseach(a[i].x1,k-1);
y=bseach(a[i].x2,k-1)-1;
if(x<=y)
update(x,y,1,k-1,1,a[i].flag);
ans+=sum[1]*(a[i+1].y-a[i].y);
}
printf("Test case #%d\n",++c);
printf("Total explored area: %.2lf\n\n",ans);
}
}