QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#206403#5505. Great ChasedkdkAC ✓537ms22316kbC++201.8kb2023-10-07 20:20:222023-10-07 20:20:24

Judging History

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

  • [2023-10-07 20:20:24]
  • 评测
  • 测评结果:AC
  • 用时:537ms
  • 内存:22316kb
  • [2023-10-07 20:20:22]
  • 提交

answer

#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <cmath>
#include <string>
#include <set>
#include <iomanip>
#define ft first
#define sd second
#define endl '\n'
#define lowbit(x) (x & (-x))
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
using PDI = pair<double, int>;
using i128 = __int128;
const double eps = 1e-9;
const int N = 1010, mod = 998244353, INF = 2147483647;
int dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1};

int n;
double v;
vector<PDI> a, b;

bool check(double t)
{
    double xa = -1e18, xb = 1e18;
    for(auto o : a)
    {
        double p = o.ft, v = o.sd;
        xa = max(xa, p + v * t);
    }
    for(auto o : b)
    {
        double p = o.ft, v = o.sd;
        xb = min(xb, p - v * t);
    }

    if(xa > xb)return true;
    else return false;
}

void solve()
{
    cin >> n >> v;
    a.clear(), b.clear();
    for(int i = 0; i < n ; i++)
    {
        double x, y;
        cin >> x >> y;
        if(x < 0)a.push_back({x, y});
        else b.push_back({x, y});
    }

    double l = 0, r = (b.back().ft - a.back().ft) / (b.back().sd + a.back().sd);
    while(r - l > r * eps)
    {
        double mid = (l + r) / 2;
        //cout << r - l << endl;
        if(check(mid))r = mid;
        else l = mid;
    }

    //cout << l << ' ' << r << ' ' << eps << endl;
    cout << l * v << endl;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int t = 1;
    cin >> t;
    cout << setprecision(20);
    while(t -- )solve();
    return 0;
}
/*
3
4 9
10 2
-7 2
-6 1
7 1
2 8
-1 7
1 6
2 3
-1000000000000 1
1000000000000 1
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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.249999981140717864
1.2307692296229877371
2999999997206.0322266

result:

ok 3 numbers

Test #2:

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

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:

145405766320.75476074
16414958964.935857773
5202715638.8253688812
321977234.05339133739
45384199189.949958801
183885744.71460151672
1708925225.2302970886
89786664923.352340698
13924365605.959119797
412975327.27695441246
965508404.11592268944
4703493415.878364563
352961619.3461766243
5575125768.90370...

result:

ok 10000 numbers

Test #3:

score: 0
Accepted
time: 537ms
memory: 3992kb

input:

93
15435 968117
4196666 184
-5069875 255
-9782648 980
-1978138 176
9333323 764
-4323540 12
-8442049 319
-5371878 137
2881306 10
-4050629 133
-4659099 59
-5189169 320
-2256647 99
-3686648 37
1059255 33
-223142 20
8040933 408
8407764 705
694547 38
-7913614 746
-3573355 132
5919585 189
-3756662 94
-795...

output:

189662921.33453005552
197971181.32380193472
997533530.92471122742
6439673169.415140152
993821598000.87243652
22727977312.779430389
34702455189.909873962
677770533.58397579193
46631726865.549171448
5446481862.0085382462
11336247444.635557175
4409370837.389673233
15681606050.008201599
14986614224.1759...

result:

ok 93 numbers

Test #4:

score: 0
Accepted
time: 525ms
memory: 22316kb

input:

5
400000 999972
172811492468 106699
171900177092 102097
194121748377 184014
190302947556 172722
183121572232 149212
196566712700 190884
171376795991 99358
522927044000 159597
-129031052077 34395
189422320931 170012
-275879974024 638546
408864707565 98475
-106703244806 368801
192128798630 178213
2915...

output:

519985220201.72174072
511413015656.01812744
424240880316.39556885
518849481115.3671875
1882496987586.5734863

result:

ok 5 numbers

Test #5:

score: 0
Accepted
time: 532ms
memory: 6592kb

input:

38
16668 999947
-3844782803 511
-210897941456 464872
618726004990 714384
-954596898686 225256
96675744 1148
-1515974078 11375
-206213840984 706184
306078847 3947
-474818331950 391451
-616022698917 561244
123378707 1540
-640636592655 406006
459201391325 908506
-733249583 5719
496163273 6238
619876911...

output:

89670748248.576461792
98630840877.416381836
29393530993.975414276
50801000769.317466736
39668001019.462463379
467846477883.29595947
30789914347.956680298
23151476827.507144928
51606123400.787979126
151713059970.35281372
100944679009.2434845
766785663813.65563965
39969642783.078353882
62341065932.768...

result:

ok 38 numbers