QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#385461 | #5809. Min Perimeter | ftt_fan_club | 5 | 39ms | 7768kb | C++14 | 2.3kb | 2024-04-10 19:31:50 | 2024-04-10 19:31:51 |
Judging History
answer
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long ll;
template <class T>
void read(T &x){
char c;
bool op = 0;
while(c = getchar(), c < '0' || c > '9')
if(c == '-') op = 1;
x = c - '0';
while(c = getchar(), c >= '0' && c <= '9')
x = x * 10 + c - '0';
if(op) x = -x;
}
template <class T>
void write(T x){
if(x < 0) putchar('-'), x = -x;
if(x >= 10) write(x / 10);
putchar('0' + x % 10);
}
const int N = 200005;
int n;
struct point {
double x, y;
bool operator < (const point &b) const{
return x < b.x;
}
point operator - (const point &b){
return (point){x - b.x, y - b.y};
}
double norm(){
return sqrt(x * x + y * y);
}
} p[N], a[N], b[N], c[N];
double calc(point x, point y, point z){
return (x - y).norm() + (y - z).norm() + (z - x).norm();
}
double solve(int l, int r){
if(l == r) return 1e20;
int mid = (l + r) >> 1;
double xmid = (p[mid].x + p[mid + 1].x) / 2;
double d = min(solve(l, mid), solve(mid + 1, r));
int pos = l, pb = 0, pc = 0, pl = l, pr = mid + 1;
while(pos <= r)
if(pl <= mid && (pr > r || p[pl].y < p[pr].y)){
if(p[pl].x > xmid - d / 2) b[++pb] = p[pl];
a[pos++] = p[pl++];
}
else{
if(p[pr].x < xmid + d / 2) c[++pc] = p[pr];
a[pos++] = p[pr++];
}
for(int i = l; i <= r; i++)
p[i] = a[i];
if(l + 1 == r) return 1e20;
for(int i = 1, j = 1; i <= pb; i++){
while(j <= pc && b[i].y - c[j].y > d / 2) j++;
for(int k = j; k <= pc && abs(b[i].y - c[k].y) < d / 2; k++)
for(int h = k + 1; h <= pc && abs(b[i].y - c[h].y) < d / 2; h++)
d = min(d, calc(b[i], c[k], c[h]));
}
for(int i = 1, j = 1; i <= pc; i++){
while(j <= pb && c[i].y - b[j].y > d / 2) j++;
for(int k = j; k <= pb && abs(c[i].y - b[k].y) < d / 2; k++)
for(int h = k + 1; h <= pb && abs(c[i].y - b[h].y) < d / 2; h++)
d = min(d, calc(c[i], b[k], b[h]));
}
return d;
}
int main(){
int T;
scanf("%d",&T);
for(int ii=1;ii<=T;ii++){
scanf("%d",&n);
for(int i = 1; i <= n; i++)
scanf("%lf%lf", &p[i].x, &p[i].y);
sort(p + 1, p + n + 1);
printf("Case #%d: %.8lf\n", ii,solve(1, n));
}
return 0;
}
详细
Subtask #1:
score: 5
Accepted
Test #1:
score: 5
Accepted
time: 39ms
memory: 7768kb
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.89301221 Case #2: 1042.84483496 Case #3: 1711142102.79132700 Case #4: 90912.29637403 Case #5: 3.41421356 Case #6: 26.15383034 Case #7: 1701.01268110 Case #8: 2865438.19199387 Case #9: 2020088.33722632 Case #10: 1792106.03729207 Case #11: 2019352.54290973 Case #12: 2530195.72801794 Case #...
result:
ok correct! (15 test cases)
Subtask #2:
score: 0
Runtime Error
Test #2:
score: 0
Runtime Error
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 ...