Ampzz 2011 Cross Spider 计算几何
原题链接:http://codeforces.com/gym/100523/attachments/download/2798/20142015-ct-s02e07-codeforces-trainings-season-2-episode-7-en.pdf
题意
给你一堆三维点,问你他们是否共面
题解
模板题,套版就好,需要注意的是共线
代码
#include<iostream> #include<cmath> #include<cstdio> #define MAX_N 100005 using namespace std; const double eps=1e-10; inline double Sqrt(double a) { return a <= 0 ? 0 : sqrt(a); } inline double Sqr(double a) { return a * a; } class Point_3 { public: double x, y, z; Point_3() { } Point_3(double xx, double yy, double zz) : x(xx), y(yy), z(zz) { } Point_3 operator-(Point_3 a) { return Point_3(x - a.x, y - a.y, z - a.z); } double Length() const { return Sqrt(Sqr(x) + Sqr(y) + Sqr(z)); } }; Point_3 Det(const Point_3 &a,const Point_3 &b) { return Point_3(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x); } double Dot(const Point_3 &a,const Point_3 &b) { return a.x * b.x + a.y * b.y + a.z * b.z; } double vlen(Point_3 P){return P.Length();} int dot_inline(Point_3 p1,Point_3 p2,Point_3 p3) { return vlen(Det(p1 - p2, p2 - p3)) < eps; } bool zero(double x) { return fabs(x) < eps; } Point_3 pvec(Point_3 s1,Point_3 s2,Point_3 s3) { return Det((s1 - s2), (s2 - s3)); } int dots_onplane(Point_3 a,Point_3 b,Point_3 c,Point_3 d) { return zero(Dot(pvec(a, b, c), d - a)); } int n; Point_3 point3[MAX_N]; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { int a, b, c; scanf("%d%d%d", &a, &b, &c); point3[i] = Point_3(a, b, c); } if (n <= 3) { cout << "TAK" << endl; return 0; } int p = -1; for (int i = 2; i < n; i++) { if (dot_inline(point3[0], point3[1], point3[i]) == 0) { p = i; break; } } if (p == -1) { cout << "TAK" << endl; return 0; } for (int i = 2; i < n; i++) { if (i == p)continue; if (dots_onplane(point3[0], point3[1], point3[p], point3[i]) == 0) { cout << "NIE" << endl; return 0; } } cout << "TAK" << endl; return 0; }