Advertisement
Dennnhhhickk

Untitled

Oct 14th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. // ConsoleApplication1.cpp: определяет точку входа для консольного приложения.
  2. //
  3.  
  4.  
  5. #include <iostream>
  6. #include <cstdlib>
  7. #include <cmath>
  8. #include <iomanip>
  9. #include <fstream>
  10. #include <cstdio>
  11.  
  12. using namespace std;
  13.  
  14. typedef long double ld;
  15. typedef long long ll;
  16.  
  17. struct tt {
  18. ld x, y, z, vx, vy, vz;
  19. };
  20.  
  21. tt a[100010];
  22. ll n;
  23. ld eps = 1e-8;
  24.  
  25. ld mn(ld a, ld b)
  26. {
  27. if (a - b > eps)
  28. return b;
  29. else
  30. return a;
  31. }
  32.  
  33. ld mx(ld a, ld b)
  34. {
  35. if (b - a > eps)
  36. return b;
  37. else
  38. return a;
  39. }
  40.  
  41. ld f(ld t)
  42. {
  43. ld mnx = 1e12, mxx = -1e12, mny = 1e12, mxy = -1e12, mnz = 1e12, mxz = -1e12;
  44. for (int i = 0; i < n; i++)
  45. {
  46. ld x = a[i].x + a[i].vx * t, y = a[i].y + a[i].vy * t, z = a[i].z + a[i].vz * t;
  47. mnx = mn(x, mnx);
  48. mny = mn(y, mny);
  49. mnz = mn(z, mnz);
  50. mxx = mx(x, mxx);
  51. mxy = mx(y, mxy);
  52. mxz = mx(z, mxz);
  53. }
  54. return mx(mxx - mnx, mx(mxy - mny, mxz - mnz));
  55. }
  56.  
  57. int main()
  58. {
  59. ios::sync_with_stdio(0);
  60. cin.tie(0);
  61. cout.tie(0);
  62. cin >> n;
  63. for (int i = 0; i < n; i++)
  64. cin >> a[i].x >> a[i].y >> a[i].z >> a[i].vx >> a[i].vy >> a[i].vz;
  65. cout << setprecision(4) << fixed;
  66. ld l = 0, r = 1e10;
  67. while (r > l + eps)
  68. {
  69. double m = (r + l) / 2;
  70.  
  71. if (f(m) > f(m + eps))
  72. l = m;
  73. else
  74. r = m;
  75. }
  76. cout << f(l) << endl;
  77.  
  78. return 0;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement