Asif_Anwar

UVA-11001

Jun 29th, 2021
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.28 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. //using namespace chrono;
  5.  
  6. typedef long long ll;
  7. typedef vector< int > vi;
  8. typedef vector< ll > V;
  9. typedef map<int, int > mp;
  10.  
  11. #define pb push_back
  12. #define FastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  13. #define F first
  14. #define S second
  15.  
  16. #define debug cout << -1 << endl;
  17. #define REP(i, a, b) for(int i=a; i<b; i++)
  18. #define f0r(i, n) for (int i = 0; i < n; ++i)
  19. #define f0r1(i, n) for (int i = 1; i <= n; ++i)
  20. #define r0f(i, n) for(int i=n-1; i>=0; i--)
  21. #define r0f1(i, n) for(int i=n; i>=1; i--)
  22. #define fore(a, x) for (auto& a : x)
  23. #define fori(i, a, b) for (int i = (a); i < (b); ++i)
  24.  
  25. #define MP make_pair
  26. #define UB upper_bound
  27. #define LB lower_bound
  28. #define nw cout << "\n"
  29.  
  30. #define issq(x) (((ll)(sqrt((x))))*((ll)(sqrt((x))))==(x))
  31. #define rev(v) reverse(v.begin(),v.end())
  32. #define asche cerr<<"Ekhane asche\n";
  33. #define rev(v) reverse(v.begin(),v.end())
  34. #define srt(v) sort(v.begin(),v.end())
  35. #define grtsrt(v) sort(v.begin(),v.end(),greater<ll>())
  36. #define all(v) v.begin(),v.end()
  37. #define mnv(v) *min_element(v.begin(),v.end())
  38. #define mxv(v) *max_element(v.begin(),v.end())
  39. #define valid(tx,ty) (tx>=0 && tx<n && ty>=0 && ty<m)
  40. #define one(x) __builtin_popcount(x)
  41. //#define pop pop_back
  42. #define setPrec(x) cout << fixed << setprecision(x)
  43. #define sz(a) (int)a.size()
  44. //#define fin cin
  45. //#define fout cout
  46. const int INF = 1e9;
  47. const ll MOD = (ll)1e9+7;
  48. const ll INFL = 1e18;
  49. const ll mnINF = -1e18;
  50. const double diff = 10e-12;
  51. const int maxn = 200005;
  52. const double PI = acos(-1);
  53. using namespace std;
  54.  
  55. // int dx[] = {-1, 0, 1};
  56. // int dy[] = {-1, 0, 1};
  57.  
  58. int dx[] = {-1, 0, 0, 1};
  59. int dy[] = {0, -1, 1, 0};
  60.  
  61.  
  62. void solve()
  63. {
  64.     double vt, v;
  65.     while(cin >> vt >> v) {
  66.         if(vt==0 && v==0) return;
  67.         if(vt<=v) {
  68.             cout << 0 << "\n";
  69.             continue;
  70.         }
  71.         vector< pair< double, int > > ans;
  72.         double mxDia = 0.00;
  73.         int mxDisc = 0;
  74.         int mnD = 1;
  75.         // cout << mnD <<  " " << mxD << "\n";
  76.         for(int vag=mnD; ; vag++) {
  77.             double ektarVol = (double)(double(vt)/vag);
  78.             if(!(ektarVol>v)) break;
  79.             double totalDia = vag * (0.3 * sqrt((double)(ektarVol - v)));
  80.             // cout << vag << " " << totalDia << "\n";
  81.             ans.pb({totalDia, vag});
  82.         }
  83.         srt(ans);
  84.         rev(ans);
  85.         if(ans.size()==1) {
  86.             cout << ans[0].S << "\n";
  87.         }
  88.         else {
  89.             if(ans[0].F==ans[1].F || abs(ans[0].F-ans[1].F<diff)) {
  90.                 cout << 0 << "\n";
  91.             }
  92.             else cout << ans[0].S << "\n";
  93.         }
  94.     }
  95. }
  96.  
  97.  
  98.  
  99. void setIO(string name = "") { // name is nonempty for USACO file I/O
  100.  
  101.     ios_base::sync_with_stdio(0); cin.tie(0); // see Fast Input & Output
  102.  
  103.     // alternatively, cin.tie(0)->sync_with_stdio(0);
  104.  
  105.     if (name.size()) {
  106.  
  107.         freopen((name+".in").c_str(), "r", stdin); // see Input & Output
  108.  
  109.         freopen((name+".out").c_str(), "w", stdout);
  110.  
  111.     }
  112.  
  113. }
  114.  
  115. int main()
  116. {
  117.     //setIO("breedflip");
  118.     FastIO;
  119.     int t;
  120.     t = 1;
  121.     // cin >> t;
  122.     f0r(i, t) {
  123.         // cin.ignore();
  124.         //cout << "Case " << i+1 << ": ";
  125.         solve();
  126.     }
  127.     return 0;
  128. }
Add Comment
Please, Sign In to add comment