QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#73271 | #2935. Spider-Fly | qdd | WA | 0ms | 3668kb | C++20 | 4.2kb | 2023-01-23 11:56:04 | 2023-01-23 11:56:23 |
Judging History
answer
// qdd on Jan 22, 2023
#ifdef qdd
#include <ringo>
#else
#include <bits/stdc++.h>
#define dbg(...)
#define dbgr(x, y)
#endif
using namespace std;
using ll = long long;
#define ALL(x) begin(x), end(x)
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
for (T& x : v) is >> x;
return is;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
bool f = 0;
for (const T& x : v) (f ? os << ' ' : os) << x, f = 1;
return os;
}
using ld = double;
ld W, H, L;
struct P {
ld x, y, z;
P() {}
P(ld x, ld y, ld z) : x(x), y(y), z(z) {}
int get_face() {
if (z == 0) return 5;
if (z == L) return 6;
if (y == 0) return 1;
if (y == H) return 3;
if (x == 0) return 2;
if (x == W) return 4;
assert(0);
}
P operator-(const P& b) const { return P(x - b.x, y - b.y, z - b.z); }
};
ostream& operator<<(ostream& os, const P& p) { return os << "(" << p.x << ", " << p.y << ", " << p.z << ")"; }
struct F {
ld x, y;
ld h, w;
ld offset_x, offset_y;
F() { offset_x = offset_y = 0; }
F(int x, int y) : x(x), y(y) { offset_x = offset_y = 0; }
F(P p) {
int f = p.get_face();
assert(f == 5 || f == 6);
h = H;
w = W;
if (f == 5) {
x = p.x;
y = p.y;
offset_x = 0;
offset_y = 0;
} else {
x = p.x;
y = H - p.y;
offset_x = 0;
offset_y = -L - H;
}
}
void rot_cw() {
ld _x = y;
ld _y = w - x;
x = _x;
y = _y;
swap(h, w);
}
void rot_ccw() {
rot_cw();
rot_cw();
rot_cw();
}
void add(ld xx, ld yy) {
offset_x += xx;
offset_x += yy;
}
ld getx() { return x + offset_x; }
ld gety() { return y + offset_y; }
};
P s, t;
ld dis(P a, P b) {
P c = a - b;
return sqrt(c.x * c.x + c.y * c.y + c.z * c.z);
}
ld dis(F a, F b) {
ld x = a.getx() - b.getx(), y = a.gety() - b.gety();
return sqrt(x * x + y * y);
}
F transform_2(P p) {
int f = p.get_face();
int x = p.x, y = p.y, z = p.z;
assert(f >= 1 && f <= 4);
if (f == 1) return F(x, z);
if (f == 2) return F(-y, z);
if (f == 3) return F(2 * W + H - x, z);
if (f == 4) return F(W + y, z);
return F();
}
ld sol2() {
F a = F(s);
vector<F> up;
for (int i = 0; i < 8; i++) {
up.push_back(a);
a.rot_cw();
a.add(a.h, 0);
}
F b = transform_2(t);
F d = b;
d.x += W * 2 + H * 2;
vector<F> down{b, d};
ld ans = 1e18;
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 2; j++) {
ans = min(ans, dis(up[i], down[j]));
}
}
return ans;
}
ld sol3() {
F a = F(s);
F b = F(t);
vector<F> up, down;
for (int i = 0; i < 8; i++) {
up.push_back(a);
a.rot_cw();
a.add(a.h, 0);
}
for (int i = 0; i < 8; i++) {
down.push_back(b);
b.rot_ccw();
b.add(b.h, b.w - b.h);
}
// for (int i = 0; i < 8; i++) {
// cout << up[i].getx() << ' ' << up[i].gety() << '\n';
// // cout << down[i].x << ' ' << down[i].y << '\n';
// cout << "---";
// }
// dbg(">>> here");
// for (int i = 0; i < 8; i++) {
// // cout << up[i].x << ' ' << up[i].y << '\n';
// cout << down[i].x << ' ' << down[i].y << '\n';
// cout << "---";
// }
ld ans = 1e18;
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
ans = min(ans, dis(up[i], down[j]));
}
}
return ans;
}
void sol() {
cin >> W >> H >> L;
cin >> s.x >> s.y >> s.z;
cin >> t.x >> t.y >> t.z;
if (s.get_face() == t.get_face()) {
cout << dis(s, t) << '\n';
return;
}
int fs = s.get_face(), ft = t.get_face();
while (fs != 5) {
tie(W, H, L) = make_tuple(H, L, W);
tie(s.x, s.y, s.z) = make_tuple(s.y, s.z, s.x);
tie(t.x, t.y, t.z) = make_tuple(t.y, t.z, t.x);
fs = s.get_face();
ft = t.get_face();
if (fs > ft) swap(fs, ft), swap(s, t);
}
// sol2
if (ft <= 4) {
cout << sol2() << '\n';
} else {
cout << sol3() << '\n';
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(6);
sol();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3668kb
input:
12 12 30 6 11 0 6 1 30
output:
40.000000
result:
wrong answer 1st lines differ - expected: '40.000', found: '40.000000'