QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#105099#5505. Great ChasekingstonduyWA 685ms3624kbC++141.8kb2023-05-12 23:03:372023-05-12 23:03:41

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-12 23:03:41]
  • 评测
  • 测评结果:WA
  • 用时:685ms
  • 内存:3624kb
  • [2023-05-12 23:03:37]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define all(x) begin(x), end(x)
#define int long long
// #define double long double
#define sz(x) (int)(x).size()

typedef pair<int, int> pii;
typedef vector<int> vi;


const int inf = (int)1e18;

double updatePos(double t, vector<pair<int, double>>& cops, int flag) {
    double pos = DBL_MAX;
    for (auto& i : cops) {
        if (pos > (i.second + i.first * t) * flag) {
            pos = (i.second + i.first * t) * flag;
        }
    }

    return pos;
}


double BinSearch(double l, double r, vector<pair<int, double>>& pos, vector<pair<int, double>>& neg) {
    double mid;
    int cnt= 100;

    while (cnt-- && r - l > 1e-12 ) {
        mid = (l + r) / 2.0;
        double posL = -1 * updatePos(mid, neg, -1);
        double posR = updatePos(mid, pos, 1);
        if (posR - posL < 0) {
            r = mid ;
        } else {
            l = mid;
        }
    }
    return mid;
}



signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    cin.exceptions(std::istream::failbit);
    // freopen("../input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);


    int t;
    cin >> t;
    while (t--) {
        int n, v;
        cin >> n >> v;
        vector<pair<int, double>> pos;
        vector<pair<int, double>> neg;
        double p;
        int vel;
        double dis = 0;
        for (int i = 0; i < n; i++) {

            cin >> p >> vel;
            dis = max(dis, abs(p));
            if (p > 0) {
                pos.push_back({ -vel, p });
            } else {
                neg.push_back({ vel, p });
            }
        }

        p = 0;

        double t = BinSearch(0, dis, pos, neg);


        cout << fixed << setprecision(10) << t * v << '\n';

    }


}

詳細信息

Test #1:

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

input:

3
4 9
10 2
-7 2
-6 1
7 1
2 8
-1 7
1 6
2 3
-1000000000000 1
1000000000000 1

output:

38.2500000000
1.2307692308
3000000000000.0000000000

result:

ok 3 numbers

Test #2:

score: -100
Wrong Answer
time: 685ms
memory: 3560kb

input:

10000
200 997007
405524182320 754760
686939601648 419804
687047488212 715566
1446157132 4594
-670522037 4673
763634629282 253755
424307411732 275041
1582708381 8473
-667425982 4622
-522841486 1427
702430907988 460271
1405423646 1060
1497754648 6227
883363410675 723547
56899800372 46435
-810216390 64...

output:

145405766328.3491210938
16414958969.7272777557
5202715639.8351840973
321977234.1563256979
45384199210.2216873169
183885744.7692307532
1708925225.2304716110
89786664971.5579528809
13924365606.2873897552
412975327.5555556417
965508404.5121016502
4703493416.2883758545
352961619.3810443282
5575125771.79...

result:

wrong answer 4566th numbers differ - expected: '1.0000010', found: '1.0000012', error = '0.0000002'