您的位置:首页 > 其它

poj 1151 Atlantis

2011-08-31 11:21 344 查看
poj 1151

Atlantis

Time Limit: 1000MSMemory Limit: 10000KB64bit IO Format: %I64d & %I64u
[Submit]
[Go
Back] [Status]

Description

There are several ancient Greek texts that contain descri_ptions 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 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.

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.

Sample Input

2
10 10 20 20
15 15 25 25.5
0


Sample Output

Test case #1
Total explored area: 180.00


[Submit]
[Go
Back] [Status]

/*

from:http://www.cppblog.com/RyanWang/archive/2009/02/22/74612.html

这道题是离散化的入门题。

问题描述:一些已知右下顶点和左上顶点坐标的矩形,这些矩形可能部分重叠,求它们所占的实际面积。

离散化

1、首先分离出所有的横坐标和纵坐标分别按升序存入数组X[
]和Y[ ]中.

2、
设数组XY[ ][ ].对于每个矩形(x1,y1)(x2,y2)确定i1,i2,j1,j2,使得,X[i1]>x1,X[i2]<=x2,Y[i1]>y1,Y[i2]>=y2令XY[ i ][ j ] = 1 (i从i1到i2,j从j1到j2)

3、统计面积:area+=XY[i][j]
*(X[i]-X[i-1])*(Y[i] – Y[i-1])

我一开始没弄明白。。。。。真是一个好的方法。。太巧妙了!

*/

#include<iostream>

using
namespace std;

double
x[201],y[201],s[101][4];

int
xy[201][201];

int
n,cas=0;

double
sum;

int
main()

{


int i,j,k;


while(cin>>n)


{


if(n==0)


break;


cas++;


k=0;


sum=0.0;


memset(xy,0,sizeof(xy));


for(i=1;i<=n;i++)


{


cin>>s[i][0]>>s[i][1]>>s[i][2]>>s[i][3];


x[k]=s[i][0];


y[k]=s[i][1];


k++;


x[k]=s[i][2];


y[k]=s[i][3];


k++;


}


sort(x,x+2*n);


sort(y,y+2*n);


for(k=1;k<=n;k++)


{


int i1,i2,j1,j2;


for(i1=0;i1<2*n;i1++)


{


if(x[i1]==s[k][0])


break;


}


for(i2=0;i2<2*n;i2++)


{


if(x[i2]==s[k][2])


break;


}


for(j1=0;j1<2*n;j1++)


{


if(y[j1]==s[k][1])


break;


}


for(j2=0;j2<2*n;j2++)


{


if(y[j2]==s[k][3])


break;


}


for(i=i1;i<i2;i++)


{


for(j=j1;j<j2;j++)


{


xy[i][j]=1;


}


}


}


for(i=0;i<2*n;i++)


{


for(j=0;j<2*n;j++)


{


sum+=xy[i][j]*(x[i+1]-x[i])*(y[j+1]-y[j]);


}


}


printf("Test case #%d\n",cas);


printf("Total explored area: %.2f\n",sum);


printf("\n");


}


system("pause");


return 0;

}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: