fork download
  1. #include <bits/stdc++.h>
  2. #define MP make_pair
  3. #define PB push_back
  4. #define int long long
  5. #define st first
  6. #define nd second
  7. #define rd third
  8. #define FOR(i, a, b) for(int i =(a); i <=(b); ++i)
  9. #define RE(i, n) FOR(i, 1, n)
  10. #define FORD(i, a, b) for(int i = (a); i >= (b); --i)
  11. #define REP(i, n) for(int i = 0;i <(n); ++i)
  12. #define VAR(v, i) __typeof(i) v=(i)
  13. #define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
  14. #define ALL(x) (x).begin(), (x).end()
  15. #define SZ(x) ((int)(x).size())
  16. #define __builtin_ctz __builtin_ctzll
  17. #define __builtin_clz __builtin_clzll
  18. #define __builtin_popcount __builtin_popcountll
  19. using namespace std;
  20. template<typename TH> void _dbg(const char* sdbg, TH h) { cerr<<sdbg<<"="<<h<<"\n"; }
  21. template<typename TH, typename... TA> void _dbg(const char* sdbg, TH h, TA... t) {
  22. while(*sdbg != ',') { cerr<<*sdbg++; } cerr<<"="<<h<<","; _dbg(sdbg+1, t...);
  23. }
  24. #ifdef LOCAL
  25. #define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
  26. #define debugv(x) {{cerr <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<"\n"; }}
  27. #else
  28. #define debug(...) (__VA_ARGS__)
  29. #define debugv(x)
  30. #define cerr if(0)cout
  31. #endif
  32. #define next ____next
  33. #define prev ____prev
  34. #define left ____left
  35. #define hash ____hash
  36. typedef long long ll;
  37. typedef long double LD;
  38. typedef pair<int, int> PII;
  39. typedef pair<ll, ll> PLL;
  40. typedef vector<int> VI;
  41. typedef vector<VI> VVI;
  42. typedef vector<ll> VLL;
  43. typedef vector<pair<int, int> > VPII;
  44. typedef vector<pair<ll, ll> > VPLL;
  45.  
  46. template<class C> void mini(C&a4, C b4){a4=min(a4, b4); }
  47. template<class C> void maxi(C&a4, C b4){a4=max(a4, b4); }
  48. template<class T1, class T2>
  49. ostream& operator<< (ostream &out, pair<T1, T2> pair) { return out << "(" << pair.first << ", " << pair.second << ")";}
  50. template<class A, class B, class C> struct Triple { A first; B second; C third;
  51. bool operator<(const Triple& t) const { if (st != t.st) return st < t.st; if (nd != t.nd) return nd < t.nd; return rd < t.rd; } };
  52. template<class T> void ResizeVec(T&, vector<int>) {}
  53. template<class T> void ResizeVec(vector<T>& vec, vector<int> sz) {
  54. vec.resize(sz[0]); sz.erase(sz.begin()); if (sz.empty()) { return; }
  55. for (T& v : vec) { ResizeVec(v, sz); }
  56. }
  57. typedef Triple<int, int, int> TIII;
  58. template<class A, class B, class C>
  59. ostream& operator<< (ostream &out, Triple<A, B, C> t) { return out << "(" << t.st << ", " << t.nd << ", " << t.rd << ")"; }
  60. template<class T> ostream& operator<<(ostream& out, vector<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
  61. template<class T> ostream& operator<<(ostream& out, set<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
  62. template<class L, class R> ostream& operator<<(ostream& out, map<L, R> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
  63.  
  64. const LD kEps = 1e-9;
  65. struct Point3 {
  66. LD x, y, z;
  67. Point3 operator+(Point3 a) { Point3 p{x + a.x, y + a.y, z + a.z}; return p; }
  68. Point3 operator-(Point3 a) { Point3 p{x - a.x, y - a.y, z - a.z}; return p; }
  69. Point3 operator*(LD a) { Point3 p{x * a, y * a, z * a}; return p; }
  70. Point3 operator/(LD a) { assert(abs(a) > kEps); Point3 p{x / a, y / a, z / a}; return p; }
  71. Point3& operator+=(Point3 a) { x += a.x; y += a.y; z += a.z; return *this; }
  72. Point3& operator-=(Point3 a) { x -= a.x; y -= a.y; z -= a.z; return *this; }
  73. Point3& operator*=(LD a) { x *= a; y *= a; z *= a; return *this;}
  74. Point3& operator/=(LD a) { assert(abs(a) > kEps); x /= a; y /= a; z /= a; return *this; }
  75. LD& operator[](int a) {
  76. if (a == 0) { return x; }
  77. if (a == 1) { return y; }
  78. if (a == 2) { return z; }
  79. assert(false);
  80. }
  81. };
  82.  
  83. LD Det(Point3 a, Point3 b, Point3 d) { // ok
  84. Point3 pts[3] = {a, b, d};
  85. LD res = 0;
  86. for (int sign : {-1, 1}) {
  87. REP (st_col, 3) {
  88. int c = st_col;
  89. LD prod = 1;
  90. REP (r, 3) {
  91. prod *= pts[r][c];
  92. c = (c + sign + 3) % 3;
  93. }
  94. res += sign * prod;
  95. }
  96. }
  97. return res;
  98. }
  99.  
  100. LD Vol(Point3 A, Point3 B, Point3 C, Point3 D) {
  101. return Det(B - A, C - A, D - A);
  102. }
  103.  
  104. struct Sol {
  105. void Test() {
  106. VVI c(3, VI(5));
  107. RE (i, 4) {
  108. REP (tr, 3) {
  109. if (!(cin>>c[tr][i])) { exit(0); }
  110. }
  111. }
  112. REP (tr, 3) {
  113. if (c[tr][1] > c[tr][2]) {
  114. RE (i, 4) {
  115. c[tr][i] *= -1;
  116. }
  117. }
  118. if (c[tr][3] > c[tr][4]) { swap(c[tr][3], c[tr][4]); }
  119. }
  120. Point3 B = {c[0][2], c[1][1], c[2][1]};
  121. Point3 C = {c[0][1], c[1][2], c[2][1]};
  122. Point3 D = {c[0][1], c[1][1], c[2][2]};
  123. LD res = 0;
  124. FOR (xi, 3, 4) {
  125. FOR (yi, 3, 4) {
  126. FOR (zi, 3, 4) {
  127. VI inds{xi, yi, zi};
  128. int sign = 1;
  129. REP (tr, 3) {
  130. if (inds[tr] == 4) { sign *= -1; }
  131. }
  132. VI inter;
  133. REP (tr, 3) {
  134. inter.PB(max(c[tr][1], c[tr][inds[tr]]));
  135. }
  136. Point3 S = {inter[0], inter[1], inter[2]};
  137. LD prod = sign;
  138. LD V = Vol(S, B, C, D);
  139. REP (tr, 3) {
  140. S[tr]++;
  141. LD Vs = Vol(S, B, C, D);
  142. S[tr]--;
  143. prod *= max((LD)0, V / (V - Vs));
  144. }
  145. res += prod / 6;
  146. }
  147. }
  148. }
  149. cout<<res<<"\n";
  150.  
  151. }
  152. };
  153. int32_t main() {
  154.  
  155. ios_base::sync_with_stdio(0);
  156. cout << fixed << setprecision(10);
  157. cerr << fixed << setprecision(10);
  158. cin.tie(0);
  159. //double beg_clock = 1.0 * clock() / CLOCKS_PER_SEC;
  160.  
  161. while (1) {
  162. Sol sol;
  163. sol.Test();
  164. }
  165.  
  166.  
  167. return 0;
  168. }
  169.  
Success #stdin #stdout 0s 5536KB
stdin
0 0 0
1 1 1
0 0 0
1 1 1
0 0 0
2 2 2
0 0 0
1 1 1
0 2 0
2 0 2
1 0 1
0 1 0
stdout
0.1666666667
0.8333333333
0.1666666667