QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#184067 | #5667. Meeting Places | ucup-team1209# | WA | 1ms | 20328kb | C++20 | 2.9kb | 2023-09-20 11:31:16 | 2023-09-20 11:31:16 |
Judging History
answer
#include<bits/stdc++.h>
using std::cin;
using std::cout;
const int N = 2005;
const int mod = (1u << 31) - 1;
const int base = 233811181;
using db = long double;
using u64 = unsigned long long;
int n, k;
int x[N], y[N];
struct vec2 {
db x, y;
db norm() const { return x * x + y * y; }
db abs() const { return sqrt(norm()); }
} a[N];
vec2 operator + (vec2 x, vec2 y) { return {x.x + y.x, x.y + y.y}; }
vec2 operator - (vec2 x, vec2 y) { return {x.x - y.x, x.y - y.y}; }
vec2 operator * (vec2 x, db y) { return {x.x * y, x.y * y}; }
vec2 operator / (vec2 x, db y) { return {x.x / y, x.y / y}; }
vec2 r90(vec2 x) { return {-x.y, x.x}; }
db operator * (vec2 x, vec2 y) { return x.x * y.y - x.y * y.x; }
struct line : vec2 {
db z;
line(db a, db b, db c) : vec2{a, b}, z(c) {}
line (vec2 a, vec2 b) : vec2(r90(b - a)), z(a * b) {}
db operator () (vec2 o) const { return x * o.x + y * o.y + z; }
line perp() const { return {y, -x, 0}; }
line para(vec2 o) const { return {x, y, z - (*this)(o)}; }
};
vec2 operator & (line x, line y) {
return vec2{vec2{x.z, x.y} * vec2{y.z, y.y}, vec2{x.x, x.z} * vec2{y.x, y.z}} / -(vec2(x) * vec2(y));
}
const db eps = 1e-8;
struct ball {
vec2 o; db r;
db in(vec2 x) {
return (x - o).abs() <= r + eps;
}
};
ball getball(vec2 x, vec2 y, vec2 z) {
db a = (x - y).norm();
db b = (x - z).norm();
db c = (y - z).norm();
if(a >= b + c) return {(x + y) / 2, sqrt(a) / 2};
if(b >= a + c) return {(x + z) / 2, sqrt(b) / 2};
if(c >= b + a) return {(z + y) / 2, sqrt(c) / 2};
line A = line(x, y).perp().para((x + y) / 2);
line B = line(z, y).perp().para((z + y) / 2);
vec2 o = A & B;
return {o, (x - o).abs()};
}
ball pb[N][N];
db dp[N][N];
int main() {
std::ios::sync_with_stdio(false), cin.tie(0);
cin >> n >> k >> x[1];
y[1] = ((u64) x[1] * base + 1) % mod;
for(int i = 2;i <= n;++i) {
x[i] = ((u64) y[i - 1] * base + 1) % mod;
y[i] = ((u64) x[i] * base + 1) % mod;
}
for(int i = 1;i <= n;++i) a[i] = {x[i], y[i]};
for(int i = 1;i <= n;++i)
for(int j = 0;j <= n;++j)
dp[i][j] = 1e18;
for(int i = 1;i <= n;++i) {
pb[i][i] = {a[i], 0};
}
for(int i = 1;i <= n;++i) {
for(int j = i + 1;j <= n;++j) {
if(pb[i][j - 1].in(a[j])) {
pb[i][j] = pb[i][j - 1];
continue;
}
if(pb[i + 1][j].in(a[i])) {
pb[i][j] = pb[i + 1][j];
continue;
}
pb[i][j] = {(a[i] + a[j]) / 2, (a[i] - a[j]).abs() / 2};
for(int k = i + 1;k < j;++k) {
ball t = getball(a[i], a[j], a[k]);
if(t.r > pb[i][j].r) pb[i][j] = t;
}
}
}
for(int i = 1;i <= n;++i) {
for(int j = i;j <= n;++j) {
if(j == n || pb[i][j].r + eps < pb[i][j + 1].r) {
for(int l = 1;l <= k;++l) {
dp[j][l] = std::min(dp[j][l], dp[i - 1][l - 1] + pb[i][j].r);
}
}
}
}
db ans = 1e18;
for(int i = k;i >= 1;--i) ans = std::min(ans, dp[n][i]);
printf("%.10Lf\n", ans);
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 20328kb
input:
100 23 213
output:
1319350480.8007326126
result:
ok found '1319350480.8007326', expected '1319350480.8007326', error '0.0000000'
Test #2:
score: 0
Accepted
time: 1ms
memory: 6024kb
input:
10 1 1060
output:
1042753143.3451676369
result:
ok found '1042753143.3451676', expected '1042753143.3451676', error '0.0000000'
Test #3:
score: 0
Accepted
time: 1ms
memory: 8016kb
input:
10 10 2373
output:
0.0000000000
result:
ok found '0.0000000', expected '0.0000000', error '-0.0000000'
Test #4:
score: 0
Accepted
time: 1ms
memory: 8064kb
input:
10 2 3396
output:
1236610536.9469230175
result:
ok found '1236610536.9469230', expected '1236610536.9469230', error '0.0000000'
Test #5:
score: 0
Accepted
time: 1ms
memory: 6016kb
input:
10 3 1998
output:
973790809.8224442005
result:
ok found '973790809.8224442', expected '973790809.8224442', error '0.0000000'
Test #6:
score: -100
Wrong Answer
time: 0ms
memory: 5980kb
input:
10 4 562
output:
718029648.2579643726
result:
wrong answer 1st numbers differ - expected: '910867389.9069330', found: '718029648.2579644', error = '0.2117078'