QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#206393#5505. Great ChasedkdkWA 1ms3704kbC++201.8kb2023-10-07 20:17:312023-10-07 20:17:32

Judging History

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

  • [2023-10-07 20:17:32]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3704kb
  • [2023-10-07 20:17:31]
  • 提交

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 = (b.back().ft - a.back().ft) / (b.back().sd + a.back().sd);
    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
*/

详细

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3704kb

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.249999953899532557
1.2307691574096679688
3000000000000

result:

wrong answer 2nd numbers differ - expected: '1.2307692', found: '1.2307692', error = '0.0000001'