这题只要根据题目,利用向量把点一个个求出来计算面积即可
不过据说有一种证明方法可以证明面积是1/7的原三角形
代码:
#include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; int t; struct Point { double x, y; Point() {} Point(double x, double y) { this->x = x; this->y = y; } void read() { scanf("%lf%lf", &x, &y); } }; 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 - A.y * B.x;} //叉积 double Area2(Point A, Point B, Point C) {return Cross(B - A, C - A);} //有向面积 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() { scanf("%d", &t); while (t--) { Point A, B, C; A.read(); B.read(); C.read(); Point D, E, F; D = (C - B) / 3 + B; E = (A - C) / 3 + C; F = (B - A) / 3 + A; Point R = GetLineIntersection(C, F - C, A, D - A); Point P = GetLineIntersection(B, E - B, A, D - A); Point Q = GetLineIntersection(C, F - C, B, E - B); printf("%d\n", (int)(fabs(Area2(P, Q, R)) / 2 + 0.5)); } return 0; }
时间: 2024-10-10 02:51:37