Ampzz 2011 Cross Spider 计算几何
生活随笔
收集整理的這篇文章主要介紹了
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; }?
轉載于:https://www.cnblogs.com/HarryGuo2012/p/4730935.html
總結
以上是生活随笔為你收集整理的Ampzz 2011 Cross Spider 计算几何的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android开发 获取父控件的高宽
- 下一篇: shell脚本复制文件夹内容到另外的文件