QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#606224 | #9227. Henry the Plumber | ucup-team3215 | WA | 1ms | 3736kb | C++23 | 2.2kb | 2024-10-02 23:31:04 | 2024-10-02 23:31:04 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
using vi = vector<int>;
using pii = array<int, 2>;
using ll = long long;
template <class T>
struct vec {
T x, y, z;
using v = vec<T>;
vec(T x = 0, T y = 0, T z = 0) : x(x), y(y), z(z) {}
T dot(v b) { return x * b.x + y * b.y + z * b.z; }
vec operator+(v b) { return v(x + b.x, y + b.y, z + b.z); }
vec operator-(v b) { return v(x - b.x, y - b.y, z - b.z); }
vec cross(v b) {
return v(y * b.z - z * b.y, -(x * b.z - z * b.x), x * b.y - y * b.x);
}
vec cross(v a, v b) { return (a - *this).cross(b - *this); }
bool isnull() { return x == 0 && y == 0 && z == 0; }
};
using vec3d = vec<ll>;
struct plane {
ll a, b, c, d;
bool onplane(vec3d v) { return v.x * a + v.y * b + v.z * c + d == 0; }
};
using fp = double;
pair<fp, fp> solve_sys2(fp a, fp b, fp e, fp c, fp d, fp f) {
return {(e * d - b * f) / (a * b - b * c),
(a * f - e * c) / (a * b - b * c)};
}
bool trysolve(fp a, fp b, fp c) {
fp d = b * b - 4 * a * c;
return d >= 0;
}
void solve() {
array<vec3d, 2> p, v;
array<plane, 2> pl;
for (int i : {0, 1}) {
cin >> p[i].x >> p[i].y >> p[i].z >> v[i].x >> v[i].y;
v[i].z = 0;
pl[i] = {v[i].x, v[i].y, 0, -(p[i].x * v[i].x + p[i].y * v[i].y)};
}
int ans = -1;
if (pl[0].onplane(p[1]) && pl[1].onplane(p[0])) {
ans = 2;
} else if (pl[0].onplane(p[1]) || pl[1].onplane(p[1])) {
ans = 3 + (p[0].z == p[1].z);
} else if (v[0].dot(v[1]) == 0) {
ans = 3;
} else if (v[0].cross(v[1]).isnull()) {
ans = 4;
} else {
auto [x, y] =
solve_sys2(pl[0].a, pl[0].b, -pl[0].d, pl[1].a, pl[1].b, -pl[1].d);
// (p[0].z - z) * (p[1].z - z)
// p[0].z * p[1].z - z * (p[0].z + p[1].z) + z2
ans = trysolve(1, -(p[0].z + p[1].z),
(p[0].x - x) * (p[1].x - x) +
(p[0].y - y) * (p[1].y - y) + p[0].z * p[1].z)
? 3
: 4;
}
cout << ans << '\n';
}
int main() {
int t;
cin >> t;
while (t--) {
solve();
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3736kb
input:
2 -1 -1 3 1 1 2 2 3 2 2 5 5 1 3 0 7 6 -2 1 -2
output:
4 3
result:
ok 2 number(s): "4 3"
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3588kb
input:
100 -13 -5 -7 -19 19 -19 -13 0 -7 15 -20 20 19 -17 18 20 -20 -1 18 -19 -18 15 -14 -19 18 19 -20 6 20 -19 -12 9 1 7 -16 -13 -14 -8 8 -13 -19 16 9 20 -19 19 -18 -11 19 -18 19 20 -8 12 20 -11 -9 18 -19 -18 8 11 -13 12 -18 18 13 8 4 -18 -16 20 17 -19 18 20 -18 -3 20 -19 -17 -20 -5 -18 -19 19 16 15 19 20...
output:
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 3 3 3 3 3
result:
wrong answer 1st numbers differ - expected: '4', found: '3'