QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#738059 | #7027. Machining Disc Rotors | SGColin# | TL | 1ms | 4252kb | C++17 | 2.5kb | 2024-11-12 17:36:56 | 2024-11-12 17:36:58 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
inline ll rd() {
ll x = 0;
bool f = 0;
char c = getchar();
for (; !isdigit(c); c = getchar()) f |= (c == '-');
for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
return f ? -x : x;
}
#define eb emplace_back
#define all(s) (s).begin(), (s).end()
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)
const ld PI = 3.1415926535897932384626433832795;
const ld a90 = atan(1) * 2;
const ld a180 = a90 * 2, a270 = a90 * 3, a360 = a90 * 4;
const ld dlt[2][2] = {0, a180, a360, a180};
inline ld angle(ld x, ld y) { // counterclockwise, start from (1, 0)
if (fabs(x) < 1e-15) return a90 * (1 + 2 * (y < 0));
else return atan(y / x) + dlt[y < 0][x < 0];
}
int testcase = 0;
inline void work() {
int n = rd();
ld R = rd();
ld R2 = R * R;
vector<pair<ld, ld>> s;
vector<pair<ld, ld>> segs;
rep(i, 1, n) {
ld x = rd(), y = rd(), rr = rd();
if (x * x + y * y >= (rr + R) * (rr + R)) continue;
ld theta0 = angle(x, y);
ld rho02 = x * x + y * y;
ld rho0 = sqrt(rho02);
ld dlt = acos((rho02 + R2 - rr * rr) / (2 * rho0 * R));
ld l = theta0 - dlt;
ld r = theta0 + dlt;
if (r > 2 * PI) {
r -= 2 * PI;
l -= 2 * PI;
}
if (l < 0) {
s.eb(l + 2 * PI, 2 * PI);
s.eb(0, r);
} else s.eb(l, r);
if (l < 0) l += 2 * PI;
if (l > 2 * PI) l -= 2 * PI;
segs.eb(l, l);
if (r < 0) r += 2 * PI;
if (r > 2 * PI) r -= 2 * PI;
segs.eb(r, r);
}
ld nw = 0;
sort(all(s));
for (auto [l, r] : s) {
if (nw != l) segs.eb(nw, l);
nw = r;
}
if (nw != 2 * PI) segs.eb(nw, 2 * PI);
auto calc = [&](ld ang) {
return sqrt(R2 * (2 - 2 * cos(ang) + 1e-10));
};
ld ans = 0;
for (auto [l1, r1] : segs)
for (auto [l2, r2] : segs) {
ld nwl = l1 - r2, nwr = r1 - l2;
ans = max(ans, calc(nwl));
ans = max(ans, calc(nwr));
if (nwl < -PI && -PI < nwr) ans = max(ans, 2 * R);
if (nwl < PI && PI < nwr) ans = max(ans, 2 * R);
}
printf("Case #%d: %.18lf\n", ++testcase, (double)ans);
}
int main() {
per(t, rd(), 1) work();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 4252kb
input:
1 3 10 0 12 10 11 -6 10 -11 -6 10
output:
Case #1: 18.611654895268902266
result:
ok 1 cases
Test #2:
score: -100
Time Limit Exceeded
input:
5000 3 1000 750 500 625 -250 -625 625 -1000 1000 1000 3 8 -6 -4 5 2 5 5 8 -8 8 1 710 426 -568 994 1 10 -8 6 15 14 931 622 -651 207 -930 438 552 931 890 743 -264 -923 671 889 -315 179 15 761 173 -440 883 81 -938 -310 170 -271 981 91 918 -88 47 136 927 26 903 29 61 -162 936 22 917 129 18 32 595 431 11...
output:
Case #1: 1998.628237537179984429 Case #2: 15.989025900297439975 Case #3: 1420.000000000000000000 Case #4: 19.843134833236405257 Case #5: 1862.000000000000000000 Case #6: 1190.000000000000000000 Case #7: 934.000000000000000000 Case #8: 542.000000000000000000 Case #9: 1808.000000000000000000 Case #10:...