QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#367541 | #7846. Glacier Travel | squishybanana | WA | 1ms | 3940kb | C++23 | 3.9kb | 2024-03-26 05:45:20 | 2024-03-26 05:45:20 |
Judging History
answer
#include <iostream>
#include <vector>
#include <cmath>
#include <functional>
#include <iomanip>
using namespace std;
using ld = long double;
using pld = pair<ld,ld>;
using pii = pair<int, int>;
const ld eps = 1e-9;
template <class T> int sgn(T x) { return (x > 0) - (x < 0); }
template<class T>
struct Point {
typedef Point P;
T x, y;
explicit Point(T x=0, T y=0) : x(x), y(y) {}
bool operator<(P p) const { return tie(x,y) < tie(p.x,p.y); }
bool operator==(P p) const { return tie(x,y)==tie(p.x,p.y); }
P operator+(P p) const { return P(x+p.x, y+p.y); }
P operator-(P p) const { return P(x-p.x, y-p.y); }
P operator*(T d) const { return P(x*d, y*d); }
P operator/(T d) const { return P(x/d, y/d); }
T dot(P p) const { return x*p.x + y*p.y; }
T cross(P p) const { return x*p.y - y*p.x; }
T cross(P a, P b) const { return (a-*this).cross(b-*this); }
T dist2() const { return x*x + y*y; }
ld dist() const { return sqrtl((ld)dist2()); }
// angle to x-axis in interval [-pi, pi]
ld angle() const { return atan2(y, x); }
P unit() const { return *this/dist(); } // makes dist()=1
P perp() const { return P(-y, x); } // rotates +90 degrees
P normal() const { return perp().unit(); }
// returns point rotated 'a' radians ccw around the origin
P rotate(ld a) const {
return P(x*cos(a)-y*sin(a),x*sin(a)+y*cos(a)); }
friend ostream& operator<<(ostream& os, P p) {
return os << "(" << p.x << "," << p.y << ")"; }
};
template<class P>
vector<P> circleLine(P c, ld r, P a, P b) {
P ab = b - a, p = a + ab * (c-a).dot(ab) / ab.dist2();
ld s = a.cross(b, c), h2 = r*r - s*s / ab.dist2();
if (h2 < 0) return {};
if (h2 == 0) return {p};
P h = ab.unit() * sqrtl(h2);
return {p - h, p + h};
}
ld gss(ld a, ld b, function<ld(ld)> f) {
ld r = (sqrtl(5)-1)/2, eps = 1e-8;
ld x1 = b - r*(b-a), x2 = a + r*(b-a);
ld f1 = f(x1), f2 = f(x2);
while (b-a > eps) {
if (f1 < f2) { //change to > to find maximum
b = x2; x2 = x1; f2 = f1;
x1 = b - r*(b-a); f1 = f(x1);
} else {
a = x1; x1 = x2; f1 = f2;
x2 = a + r*(b-a); f2 = f(x2);
}
}
return a;
}
ld s;
int n;
vector<Point<ld>> p;
int main() {
cin >> s;
s -= eps;
cin >> n;
p.resize(n);
for (auto &[i, j] : p) {
int x, y ; cin >> x >> y;
i = x;j = y;
}
for (int i = n-1; i >= 0; i--) {
p[i] = p[i] - p[0];
}
Point<ld> me = p[0], partner;
bool started = false;
int i = 0, j = -1;
const ld inf = 1e18;
ld ans = inf;
bool bum = 0;
while (i < n-1) {
if (started) {
ans = min((me-partner).dist(), ans);
}
int stepType = -1;
ld nextT = inf;
if (i < n-1) {
ld o = (me-p[i+1]).dist2();
if (o < nextT) {
stepType = 0;
nextT = o;
}
}
if (started) {
ld o = (partner - p[j+1]).dist2();
if (o < nextT) {
nextT = o;
stepType = 1;
}
auto partnerDir = (p[j+1]-p[j]).unit();
auto dir = (p[i+1]-p[i]).unit();
if (!bum) {
function<ld(ld)> dis = [&](ld t) ->ld {
return (me + dir*t - partner - partnerDir*t).dist2();
};
// weird shit
o = gss(-1, min((p[j+1]-p[j]).dist(), (p[i+1]-p[i]).dist()), dis);
if (o*o < nextT && o > 0) {
nextT = o*o;
stepType = 3;
}
}
}
else {
auto a = circleLine(Point<ld>{0, 0}, s, p[i], p[i+1]);
if (a.size()) {
ld o = (me-a[0]).dist2();
if (o < nextT) {
nextT = o;
stepType = 2;
}
}
}
nextT = sqrtl(nextT);
if (started) {
auto partnerDir = (p[j+1]-p[j]).unit();
partner = partner+partnerDir*nextT;
}
auto dir = (p[i+1]-p[i]).unit();
me = me+dir*nextT;
if (stepType == 0) {
i++;
me = p[i];
}
else if (stepType == 1) {
j++;
partner = p[j];
}
else if (stepType == 2) {
j = 0;
started = true;
partner = p[0];
}
if (stepType == 3) {
bum = true;
}
else {
bum = false;
}
}
cout << setprecision(20) << fixed << ans << endl;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3804kb
input:
5 4 20 0 10 0 10 10 0 10
output:
3.53553390522563084578
result:
ok found '3.53553', expected '3.53553', error '0.00000'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3748kb
input:
3.16227766 9 -2 4 2 4 3 1 4 4 5 1 6 4 10 2 6 1 7 4
output:
0.99999999963052603518
result:
ok found '1.00000', expected '1.00000', error '0.00000'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3940kb
input:
20 5 9 38 36 16 -5 36 -24 15 30 37
output:
2.29359576024161754965
result:
ok found '2.29360', expected '2.29360', error '0.00000'
Test #4:
score: 0
Accepted
time: 1ms
memory: 3920kb
input:
10 40 17 18 12 -5 12 -16 -10 16 7 -15 18 -18 19 15 -19 1 -18 11 -8 -12 -17 -12 5 -12 -15 -8 -10 -10 -4 4 -2 -3 15 17 -2 -9 -13 7 -12 17 15 -3 -19 -14 6 6 14 -5 -10 -15 17 -16 -11 15 9 -6 10 8 19 -1 12 -6 -18 2 14 17 9 -7 -8 -3 7 11 -12 -14 -19 4 -1 15 -17 16
output:
0.00000000494054406067
result:
ok found '0.00000', expected '0.00000', error '0.00000'
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 3924kb
input:
10 40 10 11 11 15 6 -16 -18 4 10 10 -10 16 -17 11 2 6 -6 -9 17 -7 -7 -5 10 -18 -9 9 -14 10 19 -3 -14 -3 15 -5 -3 16 -10 14 -9 -12 10 -18 10 -4 -9 -11 11 -2 9 2 12 15 2 -17 -8 -16 19 7 -19 -2 -17 7 16 -9 6 -6 8 -18 15 9 17 2 -19 12 -15 -9 1 -15 19 -12
output:
0.34451634492249548364
result:
wrong answer 1st numbers differ - expected: '0.34421', found: '0.34452', error = '0.00030'