题意不说了 ,看图就看懂了= =!
思路:
本来还想是一个纯数学计算题目,算了许久没算出来,经队友指点 恍然大悟!= =!
根据输入的A,B,C三个点坐标算出 AB BC CA 三个向量来!
再算出 AD BE CF 三个向量, 再算出 三个向量的交点来 就是 R P E
在构造一遍向量 用叉积算出面积即可!
既然输出整数, 注意四舍五入!
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib>
using namespace std;
const double eps = 1e-10;
const int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
struct Point{
double x,y;
Point(double x = 0,double y = 0):x(x),y(y){}
bool operator < (const Point& rhs) const {
return x < rhs.x || (fabs(x- rhs.x) < eps && y < rhs.y);
}
bool operator == (const Point & rhs) const {
return fabs(x - rhs.x) < eps && fabs(y - rhs.y) < eps;
}
};
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); }
double Cross(Vector A,Vector B) { return A.x*B.y - B.x*A.y; }
Point GetLineIntersection(Point P,Vector v,Point Q,Vector w){
Vector u = P-Q;
double t = Cross(w, u) / Cross(v, w);
return P + v*t;
}
int main(){
int n;
scanf("%d",&n);
for (int i = 0; i < n; ++i){
double ax,ay,bx,by,cx,cy;
scanf("%lf %lf %lf %lf %lf %lf",&ax,&ay,&bx,&by,&cx,&cy);
Point A(ax,ay);
Point B(bx,by);
Point C(cx,cy);
Vector AB = B-A;
Vector BC = C-B;
Vector CA = A-C;
Vector AD = AB + BC/3.0;
Vector BE = BC + CA/3.0;
Vector CF = CA + AB/3.0;
Point P = GetLineIntersection(A,AD,B,BE);
Point Q = GetLineIntersection(B,BE,C,CF);
Point R = GetLineIntersection(A,AD,C,CF);
Vector PQ = Q-P;
Vector PR = R-P;
double s = Cross(PQ,PR)/2.0;
printf("%d\n",(int)(s+0.5 + eps));
}
return 0;
}