QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#268773 | #7846. Glacier Travel | Yarema# | AC ✓ | 7ms | 4072kb | C++14 | 2.6kb | 2023-11-28 21:01:58 | 2023-11-28 21:02:00 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef long double db;
struct Pt
{
db x, y;
Pt operator+(const Pt& p) const
{
return {x + p.x, y + p.y};
}
Pt operator-(const Pt& p) const
{
return {x - p.x, y - p.y};
}
Pt operator*(db d) const
{
return {x * d, y * d};
}
Pt operator/(db d) const
{
return {x / d, y / d};
}
};
db sq(const Pt& p)
{
return p.x * p.x + p.y * p.y;
}
db abs(const Pt& p)
{
return sqrt(sq(p));
}
ostream& operator<<(ostream& os, const Pt& p)
{
return os << "(" << p.x << "," << p.y << ")";
}
const db phi = (3. - sqrt(5.0)) / 2.;
db f(Pt a, Pt b, Pt c, Pt d)
{
Pt vec1 = b - a;
Pt vec2 = d - c;
//cerr << "TER:\n";
//cerr << a << b << c << d << '\n';
db L = 0, R = abs(b - a);
db M1, M2, v1, v2;
M1 = L + (R - L) * phi;
M2 = R - (R - L) * phi;
v1 = abs((a + vec1 * M1) - (c + vec2 * M1));
v2 = abs((a + vec1 * M2) - (c + vec2 * M2));
FOR (i, 0, 74)
{
if (v1 > v2) // for minimum
{
L = M1;
M1 = M2;
v1 = v2;
M2 = R - (R - L) * phi;
v2 = abs((a + vec1 * M2) - (c + vec2 * M2));
}
else
{
R = M2;
M2 = M1;
v2 = v1;
M1 = L + (R - L) * phi;
v1 = abs((a + vec1 * M1) - (c + vec2 * M1));
}
}
return abs((a + vec1 * L) - (c + vec2 * L));
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout << fixed << setprecision(7 + 7 + 7);
db s;
cin >> s;
int n;
cin >> n;
vector<Pt> a(n);
FOR (i, 0, n)
cin >> a[i].x >> a[i].y;
int idx1 = 1;
int idx2 = 1;
Pt p1 = a[0];
Pt p2 = a[0];
db need = s;
FOR (i, 1, n)
{
db d = abs(a[i] - a[i - 1]);
if (d < need)
need -= d;
else
{
Pt v = a[i] - a[i - 1];
p2 = a[i - 1] + v / d * need;
idx2 = i;
break;
}
}
db ans = abs(p2 - p1);
while (idx2 < n)
{
db d1 = abs(a[idx1] - p1);
db d2 = abs(a[idx2] - p2);
if (d1 < d2)
{
Pt p = a[idx2] - a[idx2 - 1];
db d = abs(p);
Pt end = p2 + (p / d * d1);
ans = min(ans, f(p1, a[idx1], p2, end));
p1 = a[idx1];
p2 = end;
idx1++;
}
else
{
Pt p = a[idx1] - a[idx1 - 1];
db d = abs(p);
Pt end = p1 + (p / d * d2);
ans = min(ans, f(p1, end, p2, a[idx2]));
p2 = a[idx2];
p1 = end;
idx2++;
}
}
cout << ans << '\n';
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3948kb
input:
5 4 20 0 10 0 10 10 0 10
output:
3.535533905932737622126
result:
ok found '3.53553', expected '3.53553', error '0.00000'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3944kb
input:
3.16227766 9 -2 4 2 4 3 1 4 4 5 1 6 4 10 2 6 1 7 4
output:
0.999999999946753780121
result:
ok found '1.00000', expected '1.00000', error '0.00000'
Test #3:
score: 0
Accepted
time: 1ms
memory: 3904kb
input:
20 5 9 38 36 16 -5 36 -24 15 30 37
output:
2.293595760356297303837
result:
ok found '2.29360', expected '2.29360', error '0.00000'
Test #4:
score: 0
Accepted
time: 0ms
memory: 4016kb
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.000000000000012667168
result:
ok found '0.00000', expected '0.00000', error '0.00000'
Test #5:
score: 0
Accepted
time: 1ms
memory: 3848kb
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.344214437307393069710
result:
ok found '0.34421', expected '0.34421', error '0.00000'
Test #6:
score: 0
Accepted
time: 7ms
memory: 4072kb
input:
1000 4000 -720538 -681604 667325 347504 -911397 -962007 -264075 -858319 49605 149209 964851 361021 -397274 28661 -460607 -273701 104862 -136807 -803899 -693703 -974 -337735 323678 -209811 -745617 -358684 -984333 603546 722843 -444579 701511 -255784 -676477 -836480 998942 -227888 -502059 -438394 9641...
output:
0.044504743567276504718
result:
ok found '0.04450', expected '0.04450', error '0.00000'
Test #7:
score: 0
Accepted
time: 7ms
memory: 3916kb
input:
1000 4000 703 909 500 496 -214 628 914 -44 -330 -238 -1424 -1426 347 1420 332 -1417 877 1678 -1390 819 -921 525 121 -923 -851 -859 512 -151 765 -109 416 -1529 -269 667 475 -234 -708 300 1917 -1935 -909 1342 1141 -696 -272 1295 1908 -1124 -898 -1225 1608 630 -1937 1246 -255 1021 -1005 -1650 -1595 -39...
output:
0.038185710042678770576
result:
ok found '0.03819', expected '0.03819', error '0.00000'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3728kb
input:
40 3 100 0 0 100 0 0
output:
15.307337294603590867846
result:
ok found '15.30734', expected '15.30734', error '0.00000'
Test #9:
score: 0
Accepted
time: 0ms
memory: 3888kb
input:
48.2842712475 4 -10 -10 10 10 -10 10 10 -10
output:
0.000000000026941581511
result:
ok found '0.00000', expected '0.00000', error '0.00000'