UVA 11437 Triangle Fun 三角形趣题 (二维几何)

题意不说了 ,看图就看懂了= =!

思路:

本来还想是一个纯数学计算题目,算了许久没算出来,经队友指点  恍然大悟!= =!

根据输入的A,B,C三个点坐标算出 AB  BC  CA  三个向量来!

再算出  AD  BE  CF   三个向量,  再算出 三个向量的交点来 就是  R P  E

在构造一遍向量  用叉积算出面积即可!

既然输出整数, 注意四舍五入!

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib>
using namespace std;
const double eps = 1e-10;
const int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
struct Point{
    double x,y;
    Point(double x = 0,double y = 0):x(x),y(y){}
    bool operator < (const Point& rhs) const {
        return x < rhs.x || (fabs(x- rhs.x) < eps && y < rhs.y);
    }
    bool operator == (const Point & rhs) const {
        return fabs(x - rhs.x) < eps && fabs(y - rhs.y) < eps;
    }
};
typedef Point Vector;
Vector operator + (Vector A,Vector B) { return Vector(A.x+B.x,A.y + B.y); }
Vector operator - (Vector A,Vector B) { return Vector(A.x-B.x,A.y - B.y); }
Vector operator * (Vector A,double p) { return Vector(A.x*p,A.y*p); }
Vector operator / (Vector A,double p) { return Vector(A.x/p,A.y/p); }
double Cross(Vector A,Vector B) { return A.x*B.y - B.x*A.y; }
Point GetLineIntersection(Point P,Vector v,Point Q,Vector w){
    Vector u = P-Q;
    double t = Cross(w, u) / Cross(v, w);
    return P + v*t;
}
int main(){
    int n;
    scanf("%d",&n);
    for (int i = 0; i < n; ++i){
        double ax,ay,bx,by,cx,cy;
        scanf("%lf %lf %lf %lf %lf %lf",&ax,&ay,&bx,&by,&cx,&cy);
        Point A(ax,ay);
        Point B(bx,by);
        Point C(cx,cy);
        Vector AB = B-A;
        Vector BC = C-B;
        Vector CA = A-C;
        Vector AD = AB + BC/3.0;
        Vector BE = BC + CA/3.0;
        Vector CF = CA + AB/3.0;
        Point P = GetLineIntersection(A,AD,B,BE);
        Point Q = GetLineIntersection(B,BE,C,CF);
        Point R = GetLineIntersection(A,AD,C,CF);
        Vector PQ = Q-P;
        Vector PR = R-P;
        double s = Cross(PQ,PR)/2.0;
        printf("%d\n",(int)(s+0.5 + eps));
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值