Advertisement
_ash__

Untitled

Dec 29th, 2020
1,174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.21 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define Gene template< class
  5. #define Rics printer& operator,
  6. Gene c> struct rge{c b, e;};
  7. Gene c> rge<c> range(c i, c j){ return {i, j};}
  8. struct printer{
  9.     ~printer(){cerr<<endl;}
  10.     Gene c >Rics(c x){ cerr<<boolalpha<<x; return *this;}
  11.     Rics(string x){cerr<<x;return *this;}
  12.     Gene c, class d >Rics(pair<c, d> x){ return *this,"(",x.first,", ",x.second,")";}
  13.     Gene ... d, Gene ...> class c >Rics(c<d...> x){ return *this, range(begin(x), end(x));}
  14.     Gene c >Rics(rge<c> x){
  15.         *this,"["; for(auto it = x.b; it != x.e; ++it)
  16.             *this,(it==x.b?"":", "),*it; return *this,"]";}
  17. };
  18. #define debug() cerr<<"LINE "<<__LINE__<<" >> ", printer()
  19. #define dbg(x) "[",#x,": ",(x),"] "
  20. mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  21. int my_rand(int l, int r) {
  22.     return uniform_int_distribution<int>(l, r) (rng);
  23. }
  24.  
  25. const double pi = acos(-1);
  26.  
  27. const int N = 100000;
  28.  
  29. double W_V;
  30. double theta;
  31.  
  32. double f(double r) {
  33.     return sqrt(abs(W_V-1.0/(r*r)));
  34. }
  35.  
  36. double simpson_integration(double a, double b){
  37.     double h = (b - a) / N;
  38.     double s = f(a) + f(b); // a = x_0 and b = x_2n
  39.     for (int i = 1; i <= N - 1; ++i) {
  40.         double x = a + h * i;
  41.         s += f(x) * ((i & 1) ? 4 : 2);
  42.     }
  43.     s *= h / 3;
  44.     return s;
  45. }
  46.  
  47.  
  48. bool okay(double V, double W, double R) {
  49.     double WR = R*W;
  50.     if(V >= WR) return true;
  51.     W_V = W*W/(V*V);
  52.     double dev = simpson_integration(V/W, R);
  53. //    debug(), dbg(dev);
  54.     return dev <= theta;
  55. }
  56.  
  57. int main() {
  58. //    freopen("in.txt", "r", stdin);
  59.     ios::sync_with_stdio(0);
  60.     cin.tie(0);
  61.  
  62.     double X, Y;
  63.     cin >> X >> Y;
  64.     double theta0, omega0;
  65.     cin >> theta0 >> omega0;
  66.     if(theta0 > 180) theta0 -= 360;
  67.     theta0 *= pi/180.0;
  68.     double thetaP = atan2(Y, X);
  69.     theta = abs(theta0 - thetaP);
  70.     if(theta > pi) theta = 2*pi - theta;
  71.     double R = sqrt(X*X+Y*Y);
  72.  
  73.     omega0 *= pi/180.0;
  74.  
  75.     double lo = 0, hi = 1e7;
  76.     for(int itr = 1; itr <= 60; itr++) {
  77.         double mid = (lo+hi)/2.0;
  78.         if(okay(mid, omega0, R)) hi = mid;
  79.         else lo = mid;
  80.     }
  81.  
  82.     cout << setprecision(12) << fixed << lo << endl;
  83. }
  84.  
  85.  
  86.  
  87.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement