1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
| #include <iostream> #include <algorithm> #include <vector> using namespace std;
const int eps = 0; int sgn(int x) { return (abs(x) <= eps) ? 0 : (x < 0 ? -1 : 1); }
struct Point { int x, y, z; Point(int X = 0, int Y = 0, int Z = 0) { x = X, y = Y, z = Z; } Point operator - (const Point& o) const { return Point(x - o.x, y - o.y, z - o.z); } Point operator * (const Point& o) const { return Point(y * o.z - z * o.y, z * o.x - x * o.z, x * o.y - y * o.x); } int operator ^ (const Point& o) const { return x * o.x + y * o.y + z * o.z; } bool operator < (const Point& o) const { return x == o.x ? y == o.y ? z < o.z : y < o.y : x < o.x; } };
int Point2Plane(const Point& a, const Point& b, const Point& c, const Point& d) { return ((b - a) * (c - a)) ^ (d - a); }
bool colinear(const Point& a, const Point& b, const Point& c) { Point n = (a - b) * (b - c); return !sgn(n.x) && !sgn(n.y) && !sgn(n.z); }
struct Plane { Point a, b, c; };
const int inf = ~0U >> 1;
int main() { int t; cin >> t;
while (t--) { int n; cin >> n; vector<Point> p(n); for (int i = 0; i < n; i++) { cin >> p[i].x >> p[i].y >> p[i].z; } vector<int> good(1 << n); for (int bit = 1; bit < 1 << n; bit++) { vector<Plane> Convex; bool coplanar = 1; for (int i = 0; i < n; i++) if (bit >> i & 1) { for (int j = 0; j < i; j++) if (bit >> j & 1) { for (int k = 0; k < j; k++) if (bit >> k & 1) { auto& A = p[i], & B = p[j], & C = p[k]; if (colinear(A, B, C)) continue; bool ne = 0, po = 0; for (int o = 0; o < n; o++) if (bit >> o & 1) { int tmp = Point2Plane(A, B, C, p[o]); if (tmp < 0) ne = 1, coplanar = 0; if (tmp > 0) po = 1, coplanar = 0; } if (ne && po) continue; if (ne) Convex.push_back({ A, C, B }); else Convex.push_back({ A, B, C }); } } } int mask = bit; if (Convex.empty()) { Point L{ inf, inf, inf }, R{ -inf, -inf, -inf }; for (int i = 0; i < n; i++) if (bit >> i & 1) { auto& P = p[i]; if (P < L) L = P; if (R < P) R = P; } for (int i = 0; i < n; i++) if (!(bit >> i & 1)) { auto& P = p[i]; if (!colinear(L, R, P)) continue; if ((P.x - L.x) * (P.x - R.x) > 0) continue; if ((P.y - L.y) * (P.y - R.y) > 0) continue; if ((P.z - L.z) * (P.z - R.z) > 0) continue; mask |= 1 << i; } } else if (coplanar) { for (int i = 0; i < n; i++) if (!(bit >> i & 1)) { auto& P = p[i]; bool in = false; for (auto& [A, B, C] : Convex) { if (sgn(Point2Plane(A, B, C, P))) continue; if ((((B - A) * (C - A)) ^ ((B - A) * (P - A))) < 0) continue; if ((((C - B) * (A - B)) ^ ((C - B) * (P - B))) < 0) continue; if ((((A - C) * (B - C)) ^ ((A - C) * (P - C))) < 0) continue; in = true; } if (in) mask |= 1 << i; } } else { for (int i = 0; i < n; i++) if (!(bit >> i & 1)) { auto& P = p[i]; bool in = true; for (auto& [A, B, C] : Convex) { if (sgn(Point2Plane(A, B, C, P)) == -1) in = false; } if (in) mask |= 1 << i; } } good[mask] = 1; } int ans = 0; for (int i = 1; i < 1 << n; i++) { ans += good[i]; } cout << ans << "\n"; }
return 0; }
|