计算几何的题目,很简单;
自己随手敲了个,纪念下!
#include<cstdio>
#include<cmath>
using namespace std; struct point
{
double x,y;
point(double x=,double y=):x(x),y(y) { }
} a,b,c,d; point midd(point a,point b)
{
return point((a.x+b.x)/2.0,(a.y+b.y)/2.0);
}
point operator + (point a,point b)
{
return point(a.x+b.x,a.y+b.y);
}
point operator - (point a,point b)
{
return point(a.x-b.x,a.y-b.y);
}
point operator * (point a,double p)
{
return point(a.x*p,a.y*p);
}
point operator / (point b,double p)
{
return point(a.x/p,a.y/p);
}
double cross(point a,point b)
{
return a.x*b.y-b.x*a.y;
}
point getlineintersection(point p,point v,point q,point w)
{
point u=p-q;
double t=cross(w,u)/cross(v,w);
return p+v*t;
}
double area(point a,point b,point c)
{
return cross(b-a,c-a)/2.0;
}
double dis(point a,point b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
double line(point a,point b,point c,point d)
{
return dis(a,b)+dis(b,c)+dis(c,d)+dis(d,a);
} int main()
{
int t,ca;
scanf("%d",&t);
while(t--)
{
scanf("%d",&ca);
printf("%d ",ca);
a.x=0.0,a.y=0.0,b.y=0.0;
scanf("%lf%lf%lf%lf%lf",&b.x,&c.x,&c.y,&d.x,&d.y);
point dd=midd(a,b);
point aa=midd(b,c);
point cc=midd(a,d);
point bb=midd(c,d);
point aaa=getlineintersection(d,d-dd,a,a-aa);
point bbb=getlineintersection(a,aa-a,b,bb-b);
point ccc=getlineintersection(c,cc-c,b,bb-b);
point ddd=getlineintersection(c,cc-c,d,dd-d);
printf("%.3lf ",area(a,b,bbb)/160.0);
printf("%.3lf ",area(b,c,ccc)/160.0);
printf("%.3lf ",area(c,d,ddd)/160.0);
printf("%.3lf ",area(d,a,aaa)/160.0);
printf("%.3lf ",((area(ddd,aaa,bbb)+area(bbb,ccc,ddd))/160.0));
printf("%.0lf\n",ceil(line(aaa,bbb,ccc,ddd)*16.5));
}
return ;
}