首页 > 其他 > 详细

UVA 11437 - Triangle Fun 向量几何

时间:2014-02-11 01:10:56      阅读:392      评论:0      收藏:0      [点我收藏+]

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的面积。

bubuko.com,布布扣

思路:

先求出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;
}


UVA 11437 - Triangle Fun 向量几何

原文:http://blog.csdn.net/murmured/article/details/19047073

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!