标签:
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 21511 | Accepted: 8110 |
Description
Input
Output
Sample Input
2 10 10 20 20 15 15 25 25.5 0
Sample Output
Test case #1 Total explored area: 180.00
Source
#include<cstdio> #include<cstring> #include<cmath> #include<iostream> #include<algorithm> using namespace std; const int N=101; const double eps=1e-6; double ans=0,x[N<<1],y[N<<1],pos[N][4]; bool hash[N<<1][N<<1]; int cmp(const void *a,const void *b){ double *aa=(double *)a; double *bb=(double *)b; if(fabs(*aa-*bb)<=eps) return 0; else if(*aa-*bb>0) return 1; return -1; } int main(){ freopen("sh.txt","r",stdin); int i,j,k,n,x1,y1,x2,y2,cas=0; while(scanf("%d",&n)==1){ if(!n) break; for(ans=k=i=0;i<n;i++,k+=2){ scanf("%lf%lf%lf%lf",&pos[i][0],&pos[i][1],&pos[i][2],&pos[i][3]); x[k]=pos[i][0];y[k]=pos[i][1];x[k+1]=pos[i][2];y[k+1]=pos[i][3]; } memset(hash,0,sizeof hash); qsort(x,n<<1,sizeof x[0],cmp); qsort(y,n<<1,sizeof y[0],cmp); for(i=0;i<n;i++){ for(k=0;fabs(x[k]-pos[i][0])>eps;k++); x1=k; for(k=0;fabs(y[k]-pos[i][1])>eps;k++); y1=k; for(k=0;fabs(x[k]-pos[i][2])>eps;k++); x2=k; for(k=0;fabs(y[k]-pos[i][3])>eps;k++); y2=k; for(j=x1;j<x2;j++){ for(k=y1;k<y2;k++){ hash[j][k]=1; } } } for(i=0;i<2*n-1;i++){ for(j=0;j<2*n-1;j++){ ans+=hash[i][j]*(x[i+1]-x[i])*(y[j+1]-y[j]); } } printf("Test case #%d\n",++cas); printf("Total explored area: %.2lf\n\n",ans); } return 0; }
标签:
原文地址:http://www.cnblogs.com/shenben/p/5837614.html