QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#618637#5151. Bottle FlipRafat_KabirAC ✓0ms3960kbC++203.5kb2024-10-07 01:11:412024-10-07 01:11:42

Judging History

你现在查看的是最新测评结果

  • [2024-10-07 01:11:42]
  • 评测
  • 测评结果:AC
  • 用时:0ms
  • 内存:3960kb
  • [2024-10-07 01:11:41]
  • 提交

answer

#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <time.h>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <cstring>

using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <iostream>

using namespace __gnu_pbds;
using namespace std;
template <class T>
using Tree =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// to erase in multiset-> less_equal<T> and 
// s.erase(s.find_by_order(s.order_of_key(x)))
// lower_bound(x)=>(cannot use the stl lower_bound function)
// ll idx = s.order_of_key(x)
// if(idx == s.size()) -> no lower_bound
// else lb = *s.find_by_order(idx) // as 0-indexing
// idx-1 will give highest value which is strictly less than x
// for upper_bound->do the same with (x+1)

typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef tuple<ll, ll, ll> t64;
typedef vector<t64> vt64;
typedef vector<vt64> vvt64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef vector<vector<p32> > vvp32;
typedef vector<bool> vb;
ll mod =  1e9+7, MOD = 998244353;
double eps = 1e-12;
// #define forn(i,e) for(ll i = 0; i < e; i++)
#define FOR(s, e, i) for(int i = s; i <= e; i++)
// #define rforn(i,s) for(ll i = s; i >= 0; i--)
#define ROF(s ,e, i) for(int i = s; i >= e; i--)
#define coutAll(A) for(auto asdafas : A) cout <<  asdafas << " "; cout << "\n";
#define foutAll(A) for(auto asdafas : A) fout <<  asdafas << " "; cout << "\n";
#define cinAll(A) for(auto &asdafas : A) cin >>  asdafas;
#define finAll(A) for(auto &asdafas : A) fin >>  asdafas;
#define minpq priority_queue<ll, v64, greater<ll>>
#define maxpq priority_queue<ll> 
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fi first
#define se second
ll inf = LLONG_MAX;
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef pair<ll, ll> pll;
typedef pair<ll, ll> pii;
//#define MAXN 1000000
double h, r, da, dw;
double f(double hw){
    double Hw = hw/2;
    double Ha = hw+(h-hw)/2;
    double ha = h-hw;
    double com = (hw*dw*Hw+ha*da*Ha)/(hw*dw+ha*da);
    return com;
}

double ternary_search(double l, double r) {
    double eps = 1e-9;              //set the error limit here
    while (r - l > eps) {
        double m1 = l + (r - l) / 3;
        double m2 = r - (r - l) / 3;
        double f1 = f(m1);      //evaluates the function at m1
        double f2 = f(m2);      //evaluates the function at m2
        if (f1 < f2)
            r = m2;
        else
            l = m1;
    }
    return l;                    //return the maximum of f(x) in [l, r]
}
void solve(int it)
{
    cin >> h >> r >> da >> dw;
    cout << fixed << setprecision(20) << ternary_search(0, h);
}


int main()
{
    fast_cin();    
    ll t = 1;
    // cin >> t;
    for(int it=1; it<=t; it++)
    {
        //cout << "Case " << it << ": ";
        solve(it);
    }
    return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3824kb

input:

22 4 1 4

output:

7.33333335101252359323

result:

ok found '7.3333334', expected '7.3333333', error '0.0000000'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3836kb

input:

7 2 655 988

output:

3.14159427336305041578

result:

ok found '3.1415943', expected '3.1415942', error '0.0000000'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3836kb

input:

1 1 1 2

output:

0.41421357102271511019

result:

ok found '0.4142136', expected '0.4142136', error '0.0000000'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3948kb

input:

1000 1000 999 1000

output:

499.87516345234263326347

result:

ok found '499.8751635', expected '499.8749375', error '0.0000005'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3836kb

input:

1000 1000 1 1000

output:

30.65343029171408417710

result:

ok found '30.6534303', expected '30.6534300', error '0.0000000'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3952kb

input:

1 1000 1 1000

output:

0.03065342966502548200

result:

ok found '0.0306534', expected '0.0306534', error '0.0000000'

Test #7:

score: 0
Accepted
time: 0ms
memory: 3956kb

input:

1000 1000 482 483

output:

499.74101270020884157930

result:

ok found '499.7410127', expected '499.7409326', error '0.0000002'

Test #8:

score: 0
Accepted
time: 0ms
memory: 3892kb

input:

1 1000 482 483

output:

0.49974106597976342137

result:

ok found '0.4997411', expected '0.4997409', error '0.0000001'

Test #9:

score: 0
Accepted
time: 0ms
memory: 3840kb

input:

1 1000 1 2

output:

0.41421357102271511019

result:

ok found '0.4142136', expected '0.4142136', error '0.0000000'

Test #10:

score: 0
Accepted
time: 0ms
memory: 3844kb

input:

1000 1000 1 2

output:

414.21356776242760133755

result:

ok found '414.2135678', expected '414.2135624', error '0.0000000'

Test #11:

score: 0
Accepted
time: 0ms
memory: 3904kb

input:

961 1000 979 983

output:

480.01006475564889797170

result:

ok found '480.0100648', expected '480.0101932', error '0.0000003'

Test #12:

score: 0
Accepted
time: 0ms
memory: 3848kb

input:

997 1000 977 983

output:

497.73705802645986295829

result:

ok found '497.7370580', expected '497.7369880', error '0.0000001'

Test #13:

score: 0
Accepted
time: 0ms
memory: 3884kb

input:

1 928 1 66

output:

0.10960059122918310026

result:

ok found '0.1096006', expected '0.1096006', error '0.0000000'

Test #14:

score: 0
Accepted
time: 0ms
memory: 3832kb

input:

1 928 2 88

output:

0.13100580543377438048

result:

ok found '0.1310058', expected '0.1310058', error '0.0000000'

Test #15:

score: 0
Accepted
time: 0ms
memory: 3840kb

input:

1 928 3 74

output:

0.16760090722839471322

result:

ok found '0.1676009', expected '0.1676009', error '0.0000000'

Test #16:

score: 0
Accepted
time: 0ms
memory: 3896kb

input:

1 928 3 41

output:

0.21290885888830221595

result:

ok found '0.2129089', expected '0.2129089', error '0.0000000'

Test #17:

score: 0
Accepted
time: 0ms
memory: 3840kb

input:

1 928 1 12

output:

0.22400923804109570958

result:

ok found '0.2240092', expected '0.2240092', error '0.0000000'

Test #18:

score: 0
Accepted
time: 0ms
memory: 3824kb

input:

2 928 89 93

output:

0.98900984930056612399

result:

ok found '0.9890098', expected '0.9890097', error '0.0000002'

Test #19:

score: 0
Accepted
time: 0ms
memory: 3904kb

input:

7 928 51 72

output:

3.19900990847468591483

result:

ok found '3.1990099', expected '3.1990099', error '0.0000000'

Test #20:

score: 0
Accepted
time: 0ms
memory: 3836kb

input:

722 547 709 752

output:

355.68642128035315863599

result:

ok found '355.6864213', expected '355.6863918', error '0.0000001'

Test #21:

score: 0
Accepted
time: 0ms
memory: 3836kb

input:

242 742 518 920

output:

103.74290693724367429240

result:

ok found '103.7429069', expected '103.7429035', error '0.0000000'

Test #22:

score: 0
Accepted
time: 0ms
memory: 3832kb

input:

873 701 43 201

output:

276.08755848944002764256

result:

ok found '276.0875585', expected '276.0875558', error '0.0000000'

Test #23:

score: 0
Accepted
time: 0ms
memory: 3852kb

input:

268 228 527 562

output:

131.84610736077056003523

result:

ok found '131.8461074', expected '131.8460919', error '0.0000001'

Test #24:

score: 0
Accepted
time: 0ms
memory: 3908kb

input:

312 558 341 839

output:

121.46838358943644209376

result:

ok found '121.4683836', expected '121.4683851', error '0.0000000'

Test #25:

score: 0
Accepted
time: 0ms
memory: 3960kb

input:

274 85 178 364

output:

112.75649326579345199661

result:

ok found '112.7564933', expected '112.7564907', error '0.0000000'

Test #26:

score: 0
Accepted
time: 0ms
memory: 3888kb

input:

641 539 341 977

output:

238.05444114092057361631

result:

ok found '238.0544411', expected '238.0544387', error '0.0000000'

Test #27:

score: 0
Accepted
time: 0ms
memory: 3888kb

input:

245 861 438 872

output:

101.61838237218957203822

result:

ok found '101.6183824', expected '101.6183839', error '0.0000000'

Test #28:

score: 0
Accepted
time: 0ms
memory: 3840kb

input:

640 181 156 606

output:

215.41983844602893327647

result:

ok found '215.4198384', expected '215.4198349', error '0.0000000'