[恢]hdu 2056

2011-12-15 05:02:51

地址:http://acm.hdu.edu.cn/showproblem.php?pid=2056

题意:给2个矩阵的对角线坐标,求相交面积。计算几何。

代码:

# include <stdio.h>


double max(double a, double b){return a>b?a:b;}
double min(double a, double b){return a<b?a:b;}


double gao(double a, double b, double c, double d)
{
double x = max(a,c) ;
double y = min(b,d) ;
y -= x ;
return max(y,0) ;
}


int main ()
{
double t[2], b[2], l[2], r[2] ;
double x1,y1,x2,y2,x3,y3,x4,y4 ;
while (~scanf ("%lf%lf%lf%lf%lf%lf%lf%lf",
&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4))
{
t[0] = min(y1,y2) ;
t[1] = min(y3,y4) ;

b[0] = max(y1,y2) ;
b[1] = max(y3,y4) ;

l[0] = min(x1,x2) ;
l[1] = min(x3,x4) ;

r[0] = max(x1,x2) ;
r[1] = max(x3,x4) ;
printf ("%.2lf\n", gao(t[0],b[0],t[1],b[1]) *
gao(l[0],r[0],l[1],r[1])) ;
}
return 0 ;
}



posted @ 2012-01-06 15:41  Seraph2012  阅读(150)  评论(0编辑  收藏  举报