UVa 11437 - Triangle Fun

我是求出来所有点的坐标用叉积算的面积……

据说可以证明出来S△PQR = S△ABC/7

  1 #include <cstdio>
  2 #include <cmath>
  3 
  4 struct Point
  5 {
  6     double x, y;
  7     Point( double x = 0, double y = 0 ):x(x), y(y) { }
  8 };
  9 
 10 Point operator+( Point A, Point B )
 11 {
 12     return Point( A.x + B.x, A.y + B.y );
 13 }
 14 
 15 Point operator-( Point A, Point B )
 16 {
 17     return Point( A.x - B.x, A.y - B.y );
 18 }
 19 
 20 Point operator*( Point A, double p )
 21 {
 22     return Point( A.x * p, A.y * p );
 23 }
 24 
 25 Point operator/( Point A, double p )
 26 {
 27     return Point( A.x / p, A.y / p );
 28 }
 29 
 30 bool operator<( const Point& A, const Point& B )
 31 {
 32     return A.x < B.x || ( A.x == B.x && A.y < B.y );
 33 }
 34 
 35 Point Rotate( Point A, double rad )
 36 {
 37     return Point( A.x * cos(rad) - A.y * sin(rad), A.x * sin(rad) + A.y * cos(rad) );
 38 }
 39 
 40 double Cross( Point A, Point B )
 41 {
 42     return A.x * B.y - A.y * B.x;
 43 }
 44 
 45 Point GetLineIntersection( Point P, Point v, Point Q, Point w )
 46 {
 47     Point u = P - Q;
 48     double t = Cross( w, u ) / Cross( v, w );
 49     return P + v * t;
 50 }
 51 
 52 double Dot( Point A, Point B )
 53 {
 54     return A.x * B.x + A.y * B.y;
 55 }
 56 
 57 double Length( Point A )
 58 {
 59     return sqrt( Dot( A, A ) );
 60 }
 61 
 62 double Angle( Point A, Point B )
 63 {
 64     return acos( Dot(A, B) / Length(A) / Length(B) );
 65 }
 66 
 67 Point read_Point()
 68 {
 69     double x, y;
 70     scanf( "%lf%lf", &x, &y );
 71     return Point( x, y );
 72 }
 73 
 74 Point GetD( Point B, Point C )
 75 {
 76     return ( C - B ) / 3.0 + B;
 77 }
 78 
 79 int main()
 80 {
 81     Point A, B, C, D, E, F;
 82     Point P, Q, R;
 83     int T;
 84     scanf( "%d", &T );
 85     while ( T-- )
 86     {
 87         A = read_Point();
 88         B = read_Point();
 89         C = read_Point();
 90         D = GetD( B, C );
 91         E = GetD( C, A );
 92         F = GetD( A, B );
 93         Point AD = D - A;
 94         Point BE = E - B;
 95         Point CF = F - C;
 96         P = GetLineIntersection( B, BE, A, AD );
 97         Q = GetLineIntersection( C, CF, B, BE );
 98         R = GetLineIntersection( A, AD, C, CF );
 99 
100         printf( "%.0f\n", Cross( Q - P, R - P ) / 2.0 );
101     }
102     return 0;
103 }

 

posted @ 2013-06-15 20:52  冰鸮  阅读(323)  评论(0编辑  收藏  举报