QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#578942#8022. WalkeraYi_7WA 1ms3980kbC++171.9kb2024-09-20 23:22:572024-09-20 23:22:58

Judging History

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

  • [2024-09-20 23:22:58]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3980kb
  • [2024-09-20 23:22:57]
  • 提交

answer

#include <bits/stdc++.h>

#define int long long

using namespace std;

void solve() {
    double n, p1, p2, v1, v2;
    std::cin >> n >> p1 >> v1 >> p2 >> v2;

    if(p1 > p2) {
        std::swap(p1, p2);
        std::swap(v1, v2);
    }

    auto check1 = [&](double ti, double p1, double v1, double p2, double v2) {
        double l1 = p1, r1 = p1, l2 = p2, r2 = p2;
        // 1左1右
        double t = ti;
        double t1 = p1 / v1;
        if(t1 >= t) l1 -= v1 * t;
        else {
            l1 = 0.;
            t -= t1;
            r1 = std::max(r1, t * v1);
            r1 = std::min(r1, n);
        }
        t = ti;
        double t2 = (n - p2) / v2;
        if(t2 >= t) r2 += v2 * t;
        else {
            r2 = n;
            t -= t2;
            l2 = std::min(l2, n - t * v2);
            l2 = std::max(l2, 0.);
        }
        if(r1 - l1 >= n || r2 - l2 >= n || (l1 == 0 && r2 == n && l2 <= r1)) return true;
        return false;
    };

    auto check = [&](double ti) -> bool {
        if((n + std::min(p1, n - p1)) / v1 <= ti) return true;
        if((n + std::min(p2, n - p2)) / v2 <= ti) return true;
        if(check1(ti, p1, v1, p2, v2)) return true;
        double t = (p2 - p1) / (v1 + v2);
        if(ti >= t) {
            if(p1 == 0 && p2 == n) return true;
            double x = p1 + v1 * t;
            if(check1(ti - t, x, v1, x, v2)) return true;
        }

        return false;
    };

    double l = 0, r = 20000000;
    for(int i = 0; i < 200; i++) {
//        std::cout << l << ' ' << r << '\n';
        double mid = (l + r) / 2.;
        if(check(mid)) r = mid;
        else l = mid;
    }
//    printf("%.10f %.10f\n", l, r);
    printf("%.10f\n", r);
}

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

    int t = 1;
    std::cin >> t;
    for(int i = 0; i < t; ++i) {
        solve();
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
10000.0 1.0 0.001 9999.0 0.001
4306.063 4079.874 0.607 1033.423 0.847

output:

5001000.0000000000
3827.8370013755

result:

ok 2 numbers

Test #2:

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

input:

1
10.0 1.0 10.0 9.0 0.1

output:

1.1000000000

result:

ok found '1.1000000', expected '1.1000000', error '0.0000000'

Test #3:

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

input:

1
10.0 8.0 10.0 9.0 0.1

output:

1.2000000000

result:

ok found '1.2000000', expected '1.2000000', error '0.0000000'

Test #4:

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

input:

1
10.0 8.0 0.1 9.0 10

output:

1.1000000000

result:

ok found '1.1000000', expected '1.1000000', error '0.0000000'

Test #5:

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

input:

1
10.0 2.0 0.1 3.0 10

output:

1.3000000000

result:

ok found '1.3000000', expected '1.3000000', error '0.0000000'

Test #6:

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

input:

1
10.0 9.0 0.1 8.0 10.0

output:

1.2000000000

result:

ok found '1.2000000', expected '1.2000000', error '0.0000000'

Test #7:

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

input:

1
10.0 4.0 0.1 6.0 0.1

output:

60.0000000000

result:

ok found '60.0000000', expected '60.0000000', error '0.0000000'

Test #8:

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

input:

1
10.0 4.5 0.1 6.0 0.1

output:

60.0000000000

result:

wrong answer 1st numbers differ - expected: '57.5000000', found: '60.0000000', error = '0.0434783'