UVA 11437 - Triangle Fun 向量几何

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2432

题目大意:

如图,定义三角形ABC,在BC,CA,AB上分别取边D,E,F,使得CD=2BD,AE=2CE,BF=2AF,求三角形PQR的面积。


思路:

先求出D,E,F三点坐标,然后求出PQR三点坐标,最后对pr,pq进行叉乘,所得的一般即为答案。


#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const int MAXN=300+10;

struct Point 
{
  double x, y;
  Point(double x=0, double y=0):x(x),y(y) { }

};
typedef Point Vector;
Vector operator + (const Vector& A, const Vector& B) { return Vector(A.x+B.x, A.y+B.y); }
Vector operator - (const Point& A, const Point& B) { return Vector(A.x-B.x, A.y-B.y); }
Vector operator * (const Vector& A, double p) { return Vector(A.x*p, A.y*p); }
Vector operator / (const Vector& A, double p) { return Vector(A.x/p, A.y/p); }

double Cross(const Vector& A, const Vector& B) { return A.x*B.y - A.y*B.x; }

//两直线交点,参数式。
Point GetLineIntersection(const Point& P, const Vector& v, const Point& Q, const Vector& w) { 
  Vector u = P-Q;
  double t = Cross(w, u) / Cross(v, w);
  return P+v*t;
}

Point a,b,c;
int main()
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
		scanf("%lf%lf%lf%lf%lf%lf",&a.x,&a.y,&b.x,&b.y,&c.x,&c.y);
		Vector BD=(c-b)/3;
		Vector AF=(b-a)/3;
		Vector CE=(a-c)/3;
		Point d=b+BD;
		Point f=a+AF;
		Point e=c+CE;
		Point p=GetLineIntersection(d,a-d,b,b-e);
		Point q=GetLineIntersection(c,c-f,b,b-e);
		Point r=GetLineIntersection(c,c-f,d,a-d);
		printf("%.0lf\n",Cross(p-q,p-r)/2);
	}
	return 0;
}


posted @ 2014-02-10 20:24  hr_whisper  阅读(112)  评论(0编辑  收藏  举报