蓝书几何训练UVA-11437 Triangle Fun

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_36172505/article/details/82117828

题目链接:
Triangle Fun

题目大意:
给定三角形ABC,在BC,CA,AB上分别取点D,E,F,使得CD = 2BD, AE = 2CE, BF = 2AF,求三角形PQR面积

解题思路:
由梅涅劳斯定理得:如果一条直线与△ABC的三边AB、BC、CA或其延长线交于F、D、E点,那么(AF/FB)(BD/DC)(CE/EA)=1
(对于该定理,不了解的朋友可以看看这个:梅涅劳斯定理
那么对于该问题,在△ABE中,由该定理得:(AF/FB)(BQ/QE)(EC/CA)=1,因为(AF/FB)=1/2,(EC/CA) =1/3
所以,(BQ/QE) = 1/6,则S△BQC/S△QEC=1/6,则S△BEC/S△QEC = 1/7,又因为S△BEC = 1/3S,所以S△QQR=S△ABC-(S△BEC3-S△QEC3),即S△QQR = S△ABC/7
所以我们只需要求出△ABC的面积,除以7就是答案了,注意精度!!!

AC代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>

using namespace std;

struct Point{
    double x,y;
    Point(){}
    Point(double _x, double _y):x(_x),y(_y){}
};

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);
}
bool operator <(const Point &a, const Point &b){
    return a.x==b.x? a.y<b.y : a.x<b.x;
}

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 Dot(Vector A, Vector B){
    return A.x*B.x+A.y*B.y;
}
//向量的模 
double Length(Vector A){
    return sqrt(Dot(A,A));
}
//向量夹角 
double Angle(Vector A, Vector B){
    return acos(Dot(A,B)/Length(A)/Length(B));
}
//叉积 
double Cross(Vector A, Vector B){
    return A.x*B.y-A.y*B.x;
}
//向量有向面积(即三角形面积的2倍) 
double Area2(Point A, Point B, Point C){
    return Cross(B-A,C-A);
}

int main(){
    int n;
    cin>>n;
    while(n--){
        struct Point p[3];
        for(int i=0; i<3; ++i){
            double x,y;
            scanf("%lf%lf",&x,&y);
            p[i] = Point(x,y);
        }
        double area = Area2(p[0],p[1],p[2])/2.0;
//      int ans = area/7;
//      cout<<ans<<endl;
        printf("%0.f\n",area/7.0);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_36172505/article/details/82117828