QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#206385#5505. Great ChasedkdkTL 1ms3732kbC++201.7kb2023-10-07 20:14:582023-10-07 20:14:59

Judging History

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

  • [2023-10-07 20:14:59]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3732kb
  • [2023-10-07 20:14:58]
  • 提交

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-8;
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 = 1e12;
    while(r - l > 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: 3732kb

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.2499999691332917
1.2307692300213279868
3000000000000

result:

ok 3 numbers

Test #2:

score: -100
Time Limit Exceeded

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.34384155
16414958969.723367691
5202715639.8328962326
321977234.15121585131
45384199210.218589783
183885744.76918318868
1708925225.2239527702
89786664971.557052612
13924365606.286529541
412975327.55477797985
965508404.50887274742
4703493416.2839403152
352961619.37836414576
5575125771.793...

result: