QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#367873 | #8505. Almost Aligned | ucup-team1196# | TL | 6ms | 3904kb | C++23 | 4.4kb | 2024-03-26 15:57:08 | 2024-03-26 15:57:09 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
std::cin >> n;
std::vector<int> x(n + 1), y(n + 1), dx(n + 1), dy(n + 1);
for (int i = 1; i <= n; i++) {
std::cin >> x[i] >> y[i] >> dx[i] >> dy[i];
}
double l = 0, r = 1e18;
auto get = [&](double mid) {
double lx = 1e100, rx = -1e100;
double ly = 1e100, ry = -1e100;
for (int i = 1; i <= n; i++) {
double xx = (double)x[i] + mid * dx[i];
double yy = (double)y[i] + mid * dy[i];
lx = std::min(lx, xx);
rx = std::max(rx, xx);
ly = std::min(ly, yy);
ry = std::max(ry, yy);
}
return (rx - lx) * (ry - ly);
};
auto getx = [&](double mid) {
double lx = 1e100, rx = -1e100;
for (int i = 1; i <= n; i++) {
double xx = (double)x[i] + mid * dx[i];
lx = std::min(lx, xx);
rx = std::max(rx, xx);
}
return (rx - lx);
};
auto gety = [&](double mid) {
double ly = 1e100, ry = -1e100;
for (int i = 1; i <= n; i++) {
double yy = (double)y[i] + mid * dy[i];
ly = std::min(ly, yy);
ry = std::max(ry, yy);
}
return (ry - ly);
};
double ret = 1e18;
for(int d = 3; d <= 200; d++) {
l = 0, r = 1e18;
for (int i = 1; i <= 200; i++) {
double m1 = l + (r - l) / d, m2 = l + (d - 1) * (r - l) / d;
double ans1 = get(m1), ans2 = get(m2);
if (ans1 < ans2) {
r = m2;
} else {
l = m1;
}
}
double ans1 = l;
l = 0, r = 1e12;
for (int i = 1; i <= 150; i++) {
double m1 = l + (r - l) / d, m2 = l + (d - 1) * (r - l) / d;
double ans1 = getx(m1), ans2 = getx(m2);
if (ans1 < ans2) {
r = m2;
} else {
l = m1;
}
}
double ans2 = l;
l = 0, r = 1e12;
for (int i = 1; i <= 150; i++) {
double m1 = l + (r - l) / d, m2 = l + (d - 1) * (r - l) / d;
double ans1 = gety(m1), ans2 = gety(m2);
if (ans1 < ans2) {
r = m2;
} else {
l = m1;
}
}
double ans3 = l;
double MID = (ans2 + ans3) / 2;
l = ans2, r = MID;
for (int i = 1; i <= 150; i++) {
double m1 = l + (r - l) / d, m2 = l + (d - 1) * (r - l) / d;
double ans1 = get(m1), ans2 = get(m2);
if (ans1 < ans2) {
r = m2;
} else {
l = m1;
}
}
double ans4 = l;
l = MID, r = ans3;
for (int i = 1; i <= 150; i++) {
double m1 = l + (r - l) / d, m2 = l + (d - 1) * (r - l) / d;
double ans1 = get(m1), ans2 = get(m2);
if (ans1 < ans2) {
r = m2;
} else {
l = m1;
}
}
double ans5 = l;
l = ans2, r = ans3;
for (int i = 1; i <= 150; i++) {
double m1 = l + (r - l) / d, m2 = l + (d - 1) * (r - l) / d;
double ans1 = get(m1), ans2 = get(m2);
if (ans1 < ans2) {
r = m2;
} else {
l = m1;
}
}
double ans6 = l;
l = 0, r = ans2;
for (int i = 1; i <= 150; i++) {
double m1 = l + (r - l) / d, m2 = l + (d - 1) * (r - l) / d;
double ans1 = get(m1), ans2 = get(m2);
if (ans1 < ans2) {
r = m2;
} else {
l = m1;
}
}
double ans7 = l;
l = ans2, r = 1e12;
for (int i = 1; i <= 150; i++) {
double m1 = l + (r - l) / d, m2 = l + (d - 1) * (r - l) / d;
double ans1 = get(m1), ans2 = get(m2);
if (ans1 < ans2) {
r = m2;
} else {
l = m1;
}
}
double ans8 = l;
ret = std::min({ret, get(ans1), get(ans2), get(ans3), get(ans4), get(ans5), get(ans6), get(ans7), get(ans8)});
}
cout << fixed << setprecision(12) << ret << '\n';
}
详细
Test #1:
score: 100
Accepted
time: 6ms
memory: 3904kb
input:
4 0 0 10 10 0 0 10 10 10 10 -10 -10 10 0 -20 0
output:
22.222222222222
result:
ok found '22.222222222', expected '22.222222222', error '0.000000000'
Test #2:
score: 0
Accepted
time: 5ms
memory: 3808kb
input:
3 0 -1 0 2 1 1 1 1 -1 1 -1 1
output:
0.000000000000
result:
ok found '0.000000000', expected '0.000000000', error '-0.000000000'
Test #3:
score: 0
Accepted
time: 5ms
memory: 3832kb
input:
3 0 -1 0 -2 1 1 1 1 -1 1 -1 1
output:
4.000000000000
result:
ok found '4.000000000', expected '4.000000000', error '0.000000000'
Test #4:
score: 0
Accepted
time: 4ms
memory: 3868kb
input:
1 0 0 0 0
output:
0.000000000000
result:
ok found '0.000000000', expected '0.000000000', error '-0.000000000'
Test #5:
score: 0
Accepted
time: 3ms
memory: 3804kb
input:
4 1000000 1000000 -1 -1000000 1000000 -1000000 -1000000 1 -1000000 -1000000 1 1000000 -1000000 1000000 1000000 -1
output:
3999984000032.000000000000
result:
ok found '3999984000032.000000000', expected '3999984000032.000000000', error '0.000000000'
Test #6:
score: -100
Time Limit Exceeded
input:
1000000 -871226 486657 -467526 31395 -65837 846554 469710 -907814 927993 -45099 713462 -276539 261942 483255 746021 811070 63449 -779486 588838 -413687 812070 -87868 -813499 -420768 112521 -622607 -832012 921368 -182120 517379 -401743 -837524 -685985 337832 643014 135144 12895 326935 -495720 930620 ...