QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#646214#8022. Walkerkans2298WA 27ms4036kbC++174.9kb2024-10-16 21:43:482024-10-16 21:43:49

Judging History

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

  • [2024-10-16 21:43:49]
  • 评测
  • 测评结果:WA
  • 用时:27ms
  • 内存:4036kb
  • [2024-10-16 21:43:48]
  • 提交

answer

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <stdexcept>
#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
typedef i64 i128;

struct Fraction {
    i128 num;  // 分子
    i128 den;  // 分母

    Fraction(i128 num = 0, i128 den = 1) : num(num), den(den) {
        normalize();
    }

    void normalize() {
        if (den == 0) {
            throw runtime_error("Denominator is zero");
        }
          i128 n1=num,n2=den;
          if (n1<0) n1=-n1;
          if (n2<0) n2=-n2;
        i128 g = gcd(n1,n2);
        num /= g;
        den /= g;
        if (den < 0) {
            num = -num;
            den = -den;
        }
    }

    Fraction operator+(const Fraction &other) const {
        i128 n = num * other.den + other.num * den;
        i128 d = den * other.den;
        return Fraction(n, d);
    }

    Fraction operator-(const Fraction &other) const {
        i128 n = num * other.den - other.num * den;
        i128 d = den * other.den;
        return Fraction(n, d);
    }

    Fraction operator*(const Fraction &other) const {
        i128 n = num * other.num;
        i128 d = den * other.den;
        return Fraction(n, d);
    }

    Fraction operator/(const Fraction &other) const {
        if (other.num == 0) {
            throw runtime_error("Division by zero");
        }
        i128 n = num * other.den;
        i128 d = den * other.num;
        return Fraction(n, d);
    }

    bool operator<(const Fraction &other) const {
        return num * other.den < other.num * den;
    }

    bool operator<=(const Fraction &other) const {
        return num * other.den <= other.num * den;
    }

    bool operator==(const Fraction &other) const {
        return num == other.num && den == other.den;
    }

    bool operator>(const Fraction &other) const {
        return other < *this;
    }

    bool operator>=(const Fraction &other) const {
        return other <= *this;
    }

    long double to_long_double() const {
        return (long double)num / (long double)den;
    }
};

int main() {
    int ti, t;
    //freopen("input.in","r",stdin);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> t;
    for (ti = 1; ti <= t; ++ti) {
        double n_, p1_, p2_, n1_, n2_;
        cin >> n_ >> p1_ >> n1_ >> p2_ >> n2_;
        i64 n = n_ * 1000, p1 = p1_ * 1000, p2 = p2_ * 1000, n1 = n1_ * 1000, n2 = n2_ * 1000;

        if (!(p1 <= p2)) {
            swap(p1, p2);
            swap(n1, n2);
        }

        Fraction ans1(1e9, 1);
        ans1 = min(ans1, Fraction(n + min(p1, n - p1), n1));
        ans1 = min(ans1, Fraction(n + min(p2, n - p2), n2));

        auto check1 = [](i64 n, i64 p1, i64 p2, i64 n1, i64 n2) -> Fraction {
            Fraction d;
            d = Fraction(2 * n * n1 - p2 * n1 + n2 * p1, 2 * n2 + n1);
            if ((d - Fraction(p1, 1)) <= Fraction(p1, 1) && Fraction(n - p2, 1) <= (Fraction(p2, 1) - d)) {
                return d;
            }
            d = Fraction(n * n1 + p2 * n1 + n2 * p1, 2 * (n1 + n2));
            if ((d - Fraction(p1, 1)) <= Fraction(p1, 1) && (Fraction(p2, 1) - d) <= Fraction(n - p2, 1)) {
                return d;
            }
            d = Fraction(2 * n * n1 - p2 * n1 - n2 * p1, n1 + n2);
            if (Fraction(p1, 1) <= (d - Fraction(p1, 1)) && Fraction(n - p2, 1) <= (Fraction(p2, 1) - d)) {
                return d;
            }
            d = Fraction(n * n1 + p2 * n1 - n2 * p1, 2 * n1 + n2);
            if (Fraction(p1, 1) <= (d - Fraction(p1, 1)) && (Fraction(p2, 1) - d) <= Fraction(n - p2, 1)) {
                return d;
            }
            return Fraction(-1, 1);
        };

        Fraction door = check1(n, p1, p2, n1, n2);
        Fraction T(1e9, 1);
        if (p1 == p2) {
            Fraction t1 = max(Fraction(p1, n1), Fraction(n - p1, n2));
            Fraction t2 = max(Fraction(p1, n2), Fraction(n - p1, n1));
            T = min(T, min(t1, t2));
        }
        if (door > Fraction(0, 1) && Fraction(p1, 1) <= door && door <= Fraction(p2, 1)) {
            T = min(T, (door + min(door - Fraction(p1, 1), Fraction(p1, 1))) / Fraction(n1, 1));
        }
        {
            door = Fraction(p1, 1);
            Fraction tA = Fraction(p1, n1);
            Fraction tB = Fraction(n - p1 + min(n - p2, p2 - p1), n2);
            T = min(T, max(tA, tB));
        }
        {
            door = Fraction(p2, 1);
            Fraction tA = Fraction(p2 + min(p1, p2 - p1), n1);
            Fraction tB = Fraction(n - p2, n2);
            T = min(T, max(tA, tB));
        }
        {
            Fraction tA = Fraction(n - p1, n1);
            Fraction tB = Fraction(p2, n2);
            T = min(T, max(tA, tB));
        }
        long double result = min(ans1, T).to_long_double();
        cout << fixed << setprecision(8) << result << "\n";
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3864kb

input:

2
10000.0 1.0 0.001 9999.0 0.001
4306.063 4079.874 0.607 1033.423 0.847

output:

5001000.00000000
3827.83700138

result:

ok 2 numbers

Test #2:

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

input:

1
10.0 1.0 10.0 9.0 0.1

output:

1.10000000

result:

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

Test #3:

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

input:

1
10.0 8.0 10.0 9.0 0.1

output:

1.20000000

result:

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

Test #4:

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

input:

1
10.0 8.0 0.1 9.0 10

output:

1.10000000

result:

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

Test #5:

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

input:

1
10.0 2.0 0.1 3.0 10

output:

1.30000000

result:

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

Test #6:

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

input:

1
10.0 9.0 0.1 8.0 10.0

output:

1.20000000

result:

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

Test #7:

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

input:

1
10.0 4.0 0.1 6.0 0.1

output:

60.00000000

result:

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

Test #8:

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

input:

1
10.0 4.5 0.1 6.0 0.1

output:

57.50000000

result:

ok found '57.5000000', expected '57.5000000', error '0.0000000'

Test #9:

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

input:

1
10.0 1.0 1.0 8.0 1.0

output:

6.50000000

result:

ok found '6.5000000', expected '6.5000000', error '0.0000000'

Test #10:

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

input:

1
10.0 3.0 2.0 7.0 1.0

output:

4.60000000

result:

ok found '4.6000000', expected '4.6000000', error '0.0000000'

Test #11:

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

input:

1
10.0 6.0 2.0 7.0 1.0

output:

3.66666667

result:

ok found '3.6666667', expected '3.6666667', error '0.0000000'

Test #12:

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

input:

1
10.0 1.0 1.0 9.0 1.0

output:

6.00000000

result:

ok found '6.0000000', expected '6.0000000', error '0.0000000'

Test #13:

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

input:

1
10000.0 1.0 0.001 1.0 0.001

output:

9999000.00000000

result:

ok found '9999000.0000000', expected '9999000.0000000', error '0.0000000'

Test #14:

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

input:

1
10.0 5.0 1.0 5.0 1.5

output:

5.00000000

result:

ok found '5.0000000', expected '5.0000000', error '0.0000000'

Test #15:

score: -100
Wrong Answer
time: 27ms
memory: 3908kb

input:

10000
4306.063 4079.874 0.607 1033.423 0.847
8967.336 8026.500 0.398 283.019 0.876
9568.147 4481.616 0.405 800.114 0.684
9867.264 6184.040 0.312 9853.164 0.641
3344.364 730.612 0.539 1305.868 0.947
9336.180 3672.113 0.773 432.686 0.312
1468.243 59.762 0.840 1438.446 0.827
1355.133 1096.314 0.373 109...

output:

3827.83700138
7999.36499215
12559.33580247
15371.55070203
2637.69851952
9931.04151754
934.49430114
2939.17962466
5754.03288987
2847.42715700
10975.32362822
2180.27860697
23747.04545455
6278.10355487
872.39770554
10734.39564428
1005.07702889
20225.16309013
9878.00994575
22899.25925926
12241.08592593
...

result:

wrong answer 427th numbers differ - expected: '890.0298273', found: '890.0282575', error = '0.0000018'