计算几何专项:UVa 11437

求出r、p、q,然后求叉积,取绝对值再除以2就行了。第一次感受到lrj书上模板的威力,感觉好神奇!

#include <iostream>
#include <fstream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
struct point
{
    double x,y;
    point(double x=0,double y=0):x(x),y(y){}
};
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 a,double p) {return point(a.x/p,a.y/p);}
const double eps=1e-10;
int dcmp(double x)
{
    if(fabs(x)<eps) return 0;
    else return x<0?-1:1;
}
bool operator==(const point& a,const point& b)
{
    return dcmp(a.x-b.x)==0&&dcmp(a.y-b.y)==0;
}
double cross(point a,point b)
{
    return a.x*b.y-a.y*b.x;
}
point getpoint(point p,point v,point q,point w)
{
    point u=p-q;
    double t=cross(w,u)/cross(v,w);
    return p+v*t;
}
int main()
{
    freopen("in.txt","r",stdin);
    int T;
    cin>>T;
    while(T--)
    {
         double x1,y1,x2,y2,x3,y3;
         cin>>x1>>y1>>x2>>y2>>x3>>y3;
         point a=point(x1,y1);
         point b=point(x2,y2);
         point c=point(x3,y3);
         point e=point((x1+2*x3)/3,(y1+2*y3)/3);
         point d=point((x3+2*x2)/3,(y3+2*y2)/3);
         point f=point((x2+2*x1)/3,(y2+2*y1)/3);
         point r=getpoint(c,f-c,a,d-a);
         point p=getpoint(a,d-a,b,e-b);
         point q=getpoint(b,e-b,c,f-c);
         double area=fabs(cross(p-q,r-q))/2;
         printf("%.0f\n",area);
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值