QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#105097 | #5505. Great Chase | kingstonduy | WA | 619ms | 3696kb | C++14 | 1.8kb | 2023-05-12 23:01:58 | 2023-05-12 23:02:01 |
Judging History
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-9) {
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: 2ms
memory: 3696kb
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.2499999990 1.2307692245 3000000000000.0000000000
result:
ok 3 numbers
Test #2:
score: -100
Wrong Answer
time: 619ms
memory: 3568kb
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.3494262695 16414958969.7276630402 5202715639.8350362778 321977234.1563875675 45384199210.2215957642 183885744.7692240775 1708925225.2307753563 89786664971.5584564209 13924365606.2873401642 412975327.5556156635 965508404.5119117498 4703493416.2882995605 352961619.3817237616 5575125771.79...
result:
wrong answer 4566th numbers differ - expected: '1.0000010', found: '0.9993091', error = '0.0006919'