UVa 11437 (梅涅劳斯定理) Triangle Fun

题意:

给出三角形ABC顶点的坐标,DEF分别是三边的三等分点。求交点所形成的三角形PQR的面积。

分析:

根据梅涅劳斯定理,我们得到:

,解得

另外还有:,解得

所以AR : RP : PD = 3 : 3 : 1

同理,BE和CF也被分成这样比例的三段。

△ADC = (2/3)△ABC

△CDR = (4/7)△ADC

△CPR = (3/4)△CDR

△PQR = (1/2)△CPR

所以:△PQR = (1/7)△ABC

 1 #include <cstdio>
 2 #include <cmath>
 3 struct Point
 4 {
 5     double x, y;
 6     Point(double x=0, double y=0):x(x), y(y) {}
 7 };
 8 typedef Point Vector;
 9 Point operator - (const Point& a, const Point& b)
10 {
11     return Point(a.x-b.x, a.y-b.y);
12 }
13 double Cross(Vector a, Vector b)
14 {
15     return a.x*b.y - a.y*b.x;
16 }
17 double area(const Point& a, const Point& b, const Point& c)
18 {
19     return fabs(Cross(b-a, c-a)/2);
20 }
21 
22 int main()
23 {
24     //freopen("11437in.txt", "r", stdin);
25     int T;
26     scanf("%d", &T);
27     while(T--)
28     {
29         Point a, b, c;
30         scanf("%lf%lf%lf%lf%lf%lf", &a.x, &a.y, &b.x, &b.y, &c.x, &c.y);
31         double ans = area(a, b, c) / 7;
32         printf("%d
", (int)floor(ans+0.5000));
33     }
34     return 0;
35 }
代码君
原文地址:https://www.cnblogs.com/AOQNRMGYXLMV/p/4055962.html