QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#386355 | #5809. Min Perimeter | L_Hospital_ | 5 | 139ms | 8112kb | C++14 | 2.9kb | 2024-04-11 15:45:09 | 2024-04-11 15:45:09 |
Judging History
answer
#include<bits/stdc++.h>
# define int long long
# define rep(i, j, k) for (int i = j; i <= k; ++i)
# define dis(i, j) sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]))
using namespace std;
int n, x[1000005], y[1000005], dx[1000005], dy[1000005], st[1000005];
int qex[10] = {0, 1, 1, 1, -4, 3, 5, 7}, qey[10] = {1, 0, 1, -2, 9, 4, -3, 2};
bool b = true;
long double d[105][105], anx[1000005];
double ddl[1000005][21];
void solvebf()
{
long double ans = 10000000000000000LL;
rep(i, 1, n) rep(j, i + 1, n) d[i][j] = sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
rep(i, 1, n) rep(j, i + 1, n) rep(k, j + 1, n) ans = min(ans, d[i][j] + d[i][k] + d[j][k]);
cout << fixed << setprecision(15) << ans << '\n';
}
bool cmp(int a, int b){return x[a] < x[b];}
void solveeasy()
{
rep(i, 1, n) st[i] = i;
sort(st + 1, st + n + 1, cmp);
int ans = 100000000000LL;
rep(i, 1, n - 2) ans = min(ans, 2 * (x[st[i + 2]] - x[st[i]]));
cout << ans << '\n';
}
bool cmp1(int a, int b){return anx[a] < anx[b];}
void solvediff()
{
double ans = 1000000000000000LL;
rep(i, 1, n) x[i] += 1000000001, y[i] += 1000000001;
rep(i, 1, n) dx[i] = 3 * x[i] - 4 * y[i] + 10000000001LL, dy[i] = 4 * x[i] + 3 * y[i] + 10000000001LL, anx[i] = (long double) (1.0) * dx[i] + dy[i], st[i] = i;
sort(st + 1, st + n + 1, cmp1);
rep(i, 1, n) rep(k, 1, 20) if (i + k <= n) ddl[i][k] = dis(st[i], st[i + k]);
rep(i, 1, n) rep(j, i + 1, min(i + 20, n)) rep(k, j + 1, min(i + 20, n)) ans = min(ans, ddl[i][j - i] + ddl[i][k - i] + ddl[j][k - j]);
rep(i, 1, n) dx[i] = 1 * x[i] + 3 * y[i] + 10000000001LL, dy[i] = 3 * x[i] - 1 * y[i] + 10000000001LL, anx[i] = (long double) (1.0) * dx[i] + dy[i];
sort(st + 1, st + n + 1, cmp1);
rep(i, 1, n) rep(k, 1, 20) if (i + k <= n) ddl[i][k] = dis(st[i], st[i + k]);
rep(i, 1, n) rep(j, i + 1, min(i + 20, n)) rep(k, j + 1, min(i + 20, n)) ans = min(ans, ddl[i][j - i] + ddl[i][k - i] + ddl[j][k - j]);
rep(i, 1, n) dx[i] = 3 * x[i] + 1 * y[i] + 10000000001LL, dy[i] = 1 * x[i] - 3 * y[i] + 10000000001LL, anx[i] = (long double) (1.0) * dx[i] * dy[i];
sort(st + 1, st + n + 1, cmp1);
rep(i, 1, n) rep(k, 1, 20) if (i + k <= n) ddl[i][k] = dis(st[i], st[i + k]);
rep(i, 1, n) rep(j, i + 1, min(i + 20, n)) rep(k, j + 1, min(i + 20, n)) ans = min(ans, ddl[i][j - i] + ddl[i][k - i] + ddl[j][k - j]);
cout << fixed << setprecision(15) << ans << '\n';
}
signed main()
{
// freopen("triangle.in", "r", stdin);
// freopen("triangle.out", "w", stdout);
ios::sync_with_stdio(false); cin.tie(0), cout.tie(0);
int T; cin >> T; rep(tt, 1, T)
{
cout << "Case #" << tt << ": ";
cin >> n;
rep(i, 1, n) cin >> x[i] >> y[i], b &= (!y[i]);
if (n <= 100) solvebf();
else if (b) solveeasy();
else solvediff();
}
return 0;
}
详细
Subtask #1:
score: 5
Accepted
Test #1:
score: 5
Accepted
time: 139ms
memory: 8112kb
input:
15 3 2 6 7 0 3 0 3 713 269 371 79 455 421 3 91983245 637281504 756917015 312173515 869576338 436726680 10000 14761642 78236002 9047458 47951098 5238002 27761162 476182 2523742 1428546 7571226 26190010 138805810 21904372 116092132 18094916 95902196 43332562 229660522 55237112 292754072 52380020 27761...
output:
Case #1: 17.893012206204873 Case #2: 1042.844834964388099 Case #3: 1711142102.791327029466629 Case #4: 90912.296374032928725 Case #5: 3.414213562373095 Case #6: 26.153830342163694 Case #7: 1701.012681095616927 Case #8: 2865438.191993871238083 Case #9: 2020088.337226319592446 Case #10: 1792106.037292...
result:
ok correct! (15 test cases)
Subtask #2:
score: 0
Time Limit Exceeded
Test #2:
score: 0
Time Limit Exceeded
input:
15 3 501691275 344354353 167768963 536043860 249445040 557426549 4 1000000000 0 0 0 1000000000 1000000000 0 1000000000 1000000 138925776 669369648 61257680 295150640 170762328 822763944 55483472 267329456 97736936 470914328 84041848 404928904 18463588 88960924 124429360 599523280 95066048 458045504 ...