1. 程式人生 > >【ACM】杭電OJ 2056

【ACM】杭電OJ 2056

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
using namespace std;

const int maxn = 100000;
double a[4],b[4];

int main ()
{
    double l,w,x1,y1,x2,y2,x3,y3,x4,y4,x,y;
    while(scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4)!=EOF)
    {
        a[0]=x1;a[1]=x2;a[2]=x3;a[3]=x4;
        b[0]=y1;b[1]=y2;b[2]=y3;b[3]=y4;
        sort(a,a+4);
        sort(b,b+4);
        l=fabs(x1-x2)+fabs(x3-x4)-(a[3]-a[0]);
        w=fabs(y1-y2)+fabs(y3-y4)-(b[3]-b[0]);
        if(l<0 || w<0)    printf("0.00\n");
        else    printf("%.2lf\n",l*w);
    }
    return 0;
}