QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#85878 | #5667. Meeting Places | SpaceJellyfish | WA | 3ms | 4248kb | C++17 | 3.5kb | 2023-03-08 20:12:00 | 2023-03-08 20:12:02 |
Judging History
answer
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <cfloat>
#define eps 1e-9
using namespace std;
const int N = 2001, T = 5e8;
const int Mod = 2147483647;
const int base = 233811181;
int Read() {
int x = 0, f = 1;
char ch = getchar();
while (!isdigit(ch) && ch != '-')
ch = getchar();
if (ch == '-')
f = -1, ch = getchar();
while (isdigit(ch))
x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
return (f == -1) ? -x : x;
}
int n, k, x[N], y[N];
double r;
struct point {
double x, y;
} p[N], o;
double sqr(double x) { return x * x; }
double dis(point a, point b) {
return sqrt(sqr(a.x - b.x) + sqr(a.y - b.y));
}
bool cmp(double a, double b) { return fabs(a - b) < eps; }
double s[N][N];
point geto(point a, point b, point c) {
double a1, a2, b1, b2, c1, c2;
point ans;
a1 = 2 * (b.x - a.x), b1 = 2 * (b.y - a.y),
c1 = sqr(b.x) - sqr(a.x) + sqr(b.y) - sqr(a.y);
a2 = 2 * (c.x - a.x), b2 = 2 * (c.y - a.y),
c2 = sqr(c.x) - sqr(a.x) + sqr(c.y) - sqr(a.y);
if (cmp(a1, 0)) {
ans.y = c1 / b1;
ans.x = (c2 - ans.y * b2) / a2;
} else if (cmp(b1, 0)) {
ans.x = c1 / a1;
ans.y = (c2 - ans.x * a2) / b2;
} else {
ans.x = (c2 * b1 - c1 * b2) / (a2 * b1 - a1 * b2);
ans.y = (c2 * a1 - c1 * a2) / (b2 * a1 - b1 * a2);
}
return ans;
}
double dp_before[N], dp_cur[N];
void compute(int l, int r, int optl, int optr) {
if (l > r) return;
int mid = (l + r) >> 1;
pair<double, int> best = {DBL_MAX, -1};
for (int k = optl; k <= min(mid, optr); k++) {
best = min(best, {dp_before[k] + s[k + 1][mid], k});
}
dp_cur[mid] = best.first;
int opt = best.second;
compute(l, mid - 1, optl, opt);
compute(mid + 1, r, opt, optr);
}
signed main() {
n = Read(), k = Read(), x[1] = Read();
y[1] = (1ll * x[1] * base + 1) % Mod;
for (int i = 2; i <= n; i++) {
x[i] = (1ll * y[i - 1] * base + 1) % Mod;
y[i] = (1ll * x[i] * base + 1) % Mod;
p[i].x = x[i];
p[i].y = y[i];
}
double ans = 0;
for (int l = n; l > 0; l--) {
r = 0;
o = p[l];
for (int i = l; i <= n; i++) {
if (dis(o, p[i]) < r || cmp(dis(o, p[i]), r)){
s[l][i] = r;
continue;
}
o.x = (p[i].x + p[l].x) / 2;
o.y = (p[i].y + p[l].y) / 2;
r = dis(p[i], p[l]) / 2;
for (int j = l + 1; j < i; j++) {
if (dis(o, p[j]) < r || cmp(dis(o, p[j]), r))
continue;
o.x = (p[i].x + p[j].x) / 2;
o.y = (p[i].y + p[j].y) / 2;
r = dis(p[i], p[j]) / 2;
for (int k = l; k < j; k++) {
if (dis(o, p[k]) < r || cmp(dis(o, p[k]), r))
continue;
o = geto(p[i], p[j], p[k]);
r = dis(o, p[i]);
}
}
s[l][i] = r;
}
}
for (int i = 1; i <= n; i++)
dp_cur[i] = DBL_MAX;
int t = T / (n * k);
while (k--) {
memcpy(dp_before, dp_cur, sizeof(dp_cur));
// compute(1, n, 0, n - 1);
for (int i = 1; i <= n; i++)
for (int d = 1; i - d >= 0; d++)
dp_cur[i] = min(dp_cur[i], dp_before[i - d] + s[i - d + 1][i]);
}
printf("%.10lf", dp_cur[n]);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 4248kb
input:
100 23 213
output:
1319350480.8007326126
result:
ok found '1319350480.8007326', expected '1319350480.8007326', error '0.0000000'
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3768kb
input:
10 1 1060
output:
1173629081.9579613209
result:
wrong answer 1st numbers differ - expected: '1042753143.3451676', found: '1173629081.9579613', error = '0.1255100'