QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#501116#5151. Bottle FlipxixuWA 0ms3920kbC++201.1kb2024-08-02 14:27:422024-08-02 14:27:44

Judging History

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

  • [2024-08-02 14:27:44]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3920kb
  • [2024-08-02 14:27:42]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
// #define int long long
typedef long long ll;
typedef pair<int , int> PII;


const int N = 1e5 + 10;

int h , r , da , dw;

long double an(long double x)
{
    long double ans;
    ans = ((dw - da) * x * x + da * h * h) / (2 * ((dw - da) * x + da * h));
    return ans;
}

bool che(long double x)
{
    long double lo = x - 1e-8;
    if(an(lo) < an(x)) return true;
    return false;
}

void solve()
{
    cin >> h >> r >> da >> dw;

    long double l = 0 , r = h;

        // const double eps = 1e-6;   // eps 表示精度,取决于题目对精度的要求
        while (r - l > 1e-9)
        {
            
            long double mid = (l + r) / 2;
            // cout << mid << '\n';
            // cout << che(mid) << '\n';
            if(che(mid)) r = mid;
            else l = mid;
        }
        
        cout << fixed << setprecision(12) << l << '\n';





}



signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int t = 1;
    // cin >> t;
    while(t --)
    {
        solve();
    }

    return 0;
}

详细

Test #1:

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

input:

22 4 1 4

output:

7.333333336748

result:

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

Test #2:

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

input:

7 2 655 988

output:

3.141594176763

result:

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

Test #3:

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

input:

1 1 1 2

output:

0.414213567041

result:

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

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 3880kb

input:

1000 1000 999 1000

output:

499.877303955145

result:

wrong answer 1st numbers differ - expected: '499.8749375', found: '499.8773040', error = '0.0000047'