| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
200的数据范围。。。直接暴力,又快又稳贴一下暴力代码(码风辣鸡,能过凑合看吧)
#include<cstdio>
#include<cstring>
#include<algorithm>
struct jl{
double x1,y1,x2,y2;
};
jl dt[105];
int n,s;
double a;
double x[205],y[205];
bool p[205][205];
int main(){
while(scanf("%d",&n),n){
memset(p,0,sizeof(p));
a=0.0;
for(int i=1;i<=n;i++){
scanf("%lf%lf%lf%lf",&dt[i].x1,&dt[i].y1,&dt[i].x2,&dt[i].y2);
x[i*2]=dt[i].x1;
x[i*2-1]=dt[i].x2;
y[i*2]=dt[i].y1;
y[i*2-1]=dt[i].y2;
}
std::sort(x+1,x+1+n*2);
std::sort(y+1,y+1+n*2);
for(int i=1;i<=n;i++){
for(int j=1;j<n*2;j++){
if(dt[i].x2<=x[j])break;
if(dt[i].x1>=x[j+1])continue;
for(int k=1;k<n*2;k++){
if(dt[i].y2<=y[k])break;
if(dt[i].y1>=y[k+1])continue;
p[j][k]=true;
}
}
}
for(int i=1;i<n*2;i++){
double b=x[i+1]-x[i];
for(int j=1;j<n*2;j++){
if(p[i][j]){
a+=((double)y[j+1]-y[j])*b;
}
}
}
printf("Test case #%d\nTotal explored area: %.2f\n\n",++s,a);
}
return 0;
}
(记得两个换行\n\n)
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator