QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#617873 | #9227. Henry the Plumber | ucup-team5062# | WA | 1ms | 3804kb | C++17 | 3.6kb | 2024-10-06 17:28:16 | 2024-10-06 17:28:16 |
Judging History
answer
#include <cmath>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
const long double EPS = 1.0e-11;
class point {
public:
long double x, y;
point() : x(0), y(0) {}
point(long double x_, long double y_) : x(x_), y(y_) {}
point& operator+=(const point& p) { x += p.x; y += p.y; return *this; }
point& operator-=(const point& p) { x -= p.x; y -= p.y; return *this; }
point& operator*=(long double v) { x *= v; y *= v; return *this; }
point& operator/=(long double v) { x /= v; y /= v; return *this; }
point operator+(const point& p) const { return point(*this) += p; }
point operator-(const point& p) const { return point(*this) -= p; }
point operator*(long double v) const { return point(*this) *= v; }
point operator/(long double v) const { return point(*this) /= v; }
long double abs() const { return sqrt(x * x + y * y); }
long double dot(const point& p) const { return x * p.x + y * p.y; }
long double cross(const point& p) const { return x * p.y - y * p.x; }
point rotate90() const { return point(y, -x); }
};
class point3d {
public:
double x, y, z;
point3d() : x(0), y(0), z(0) {}
point3d(double x_, double y_, double z_) : x(x_), y(y_), z(z_) {}
point3d& operator+=(const point3d& p) { x += p.x; y += p.y; z += p.z; return *this; }
point3d& operator-=(const point3d& p) { x -= p.x; y -= p.y; z -= p.z; return *this; }
point3d& operator*=(long double v) { x *= v; y *= v; z *= v; return *this; }
point3d& operator/=(long double v) { x /= v; y /= v; z /= v; return *this; }
point3d operator+(const point3d& p) const { return point3d(*this) += p; }
point3d operator-(const point3d& p) const { return point3d(*this) -= p; }
point3d operator*(long double v) const { return point3d(*this) *= v; }
point3d operator/(long double v) const { return point3d(*this) /= v; }
long double abs() const { return sqrt(x * x + y * y + z * z); }
string to_string() const {
return "(" + std::to_string(x) + ", " + std::to_string(y) + ", " + std::to_string(z) + ")";
}
};
point cross_point(const point& s0, const point& s1, const point& t0, const point& t1) {
long double z = (t0 - s0).cross(t1 - t0) / (s1 - s0).cross(t1 - t0);
return s0 + (s1 - s0) * z;
}
bool check(const point& p1, const point& p2, const point& p3, const point& p4, long double z1, long double z3) {
// check parallel case
if (p2.cross(p4) == 0) {
return (p3 - p1).dot(p2) == 0;
}
// check for non-parallel case
auto sqr = [&](long double x) -> long double {
return x * x;
};
point3d q1(p1.x, p1.y, z1);
point3d q3(p3.x, p3.y, z3);
point z = cross_point(p1, p1 + p2.rotate90(), p3, p3 + p4.rotate90());
point3d mp = (q1 + q3) / 2;
long double r = (q3 - q1).abs() / 2;
long double d = (z - point(mp.x, mp.y)).abs();
if (d > r + EPS) {
return false;
}
long double delta = sqrt(r * r - d * d);
point3d s1(z.x, z.y, mp.z + delta);
point3d s2(z.x, z.y, mp.z - delta);
return ((s1 - q1).abs() > EPS && (s1 - q3).abs() > EPS) || ((s2 - q1).abs() > EPS && (s2 - q3).abs() > EPS);
}
int solve(const point& p1, const point& p2, const point& p3, const point& p4, long double z1, long double z3) {
// case for answer = 2
if ((p3 - p1).dot(p2) == 0 && (p1 - p3).dot(p4) == 0) {
return 2;
}
// case for answer = 3
if (check(p1, p2, p3, p4, z1, z3)) {
return 3;
}
return 4;
}
int main() {
int T;
cin >> T;
for (int id = 1; id <= T; id++) {
point p1, p2, p3, p4; long double z1, z3;
cin >> p1.x >> p1.y >> z1 >> p2.x >> p2.y;
cin >> p3.x >> p3.y >> z3 >> p4.x >> p4.y;
int res = solve(p1, p2, p3, p4, z1, z3);
cout << res << endl;
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3776kb
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: 0
Accepted
time: 0ms
memory: 3736kb
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:
4 4 4 4 4 4 3 4 4 4 3 4 4 3 3 4 3 4 4 4 4 4 4 4 4 4 4 4 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 3 4 4 4 4 4 3 4 3 4 4 4 3 4 4 4 4 4 4 4 3 4 3 4 4 4 4 4 4 4 4 4 4 4 4 3 4 4 4 4 4 4 4 3 3 4 3 4 4 4 4 4 4 4 4 4
result:
ok 100 numbers
Test #3:
score: 0
Accepted
time: 1ms
memory: 3784kb
input:
100 20 -9 -19 9 13 -12 14 -18 -17 12 2 -3 -2 2 -19 -8 9 -15 -19 3 -16 -16 -18 2 15 19 17 -6 -10 11 14 -20 -6 -19 7 -17 -8 -1 -7 -15 7 -15 3 2 13 -15 -9 11 15 2 -17 20 13 11 -8 -12 18 16 -18 -17 -17 15 -2 -20 1 8 -6 0 -16 -19 -5 -14 16 -17 10 -7 -16 17 -10 -13 1 1 -13 17 11 -3 -3 -18 4 -17 19 -6 -17 ...
output:
3 4 4 4 3 3 4 3 3 4 4 3 4 4 3 3 4 3 4 4 4 4 3 4 3 4 4 3 3 4 4 4 3 4 3 3 4 3 3 4 3 4 3 4 3 4 3 4 4 3 3 4 3 3 4 3 3 4 4 3 3 4 4 3 4 3 3 4 3 3 3 4 3 4 3 4 3 4 3 4 4 3 3 4 3 4 4 4 4 3 3 3 3 4 3 3 4 4 4 4
result:
ok 100 numbers
Test #4:
score: 0
Accepted
time: 1ms
memory: 3792kb
input:
100 10 -9 -13 8 -7 -3 3 -15 -5 11 -14 -20 -17 13 -13 3 20 16 -20 8 -2 -15 -20 8 20 20 -10 15 12 6 4 2 20 14 14 -13 6 -20 -10 20 -18 -15 19 10 9 4 18 -11 -16 -15 20 -11 6 15 -10 -17 -19 -6 -6 8 -19 -19 -18 -11 -9 -6 4 18 11 -5 2 -18 20 0 -12 -10 -18 -17 20 -20 19 19 17 2 -11 -20 2 -16 -19 13 -6 6 -5 ...
output:
4 3 4 3 4 4 3 3 3 4 4 3 3 3 4 4 3 3 3 4 4 4 3 4 3 3 3 3 4 4 3 4 4 3 4 3 3 4 4 3 3 3 4 4 3 4 4 4 4 4 3 4 3 4 4 4 3 4 4 3 4 4 3 3 3 4 3 3 3 3 4 4 4 4 3 4 4 3 4 3 4 3 3 3 4 4 3 4 3 4 4 3 4 3 4 4 3 3 4 4
result:
ok 100 numbers
Test #5:
score: 0
Accepted
time: 1ms
memory: 3792kb
input:
100 4 -19 -4 4 18 -15 20 -15 -16 18 -11 -10 -13 -7 14 20 -17 0 6 -20 -12 18 -8 3 -14 20 16 17 10 17 0 19 -17 -11 6 18 -19 -7 13 -13 -17 17 -17 -5 -1 17 -13 19 -10 -12 9 -3 -19 -12 -2 -16 11 13 12 -8 17 12 11 -1 20 13 -14 -5 -4 16 -20 8 -16 16 -3 9 -3 -6 14 -12 16 4 9 -16 -10 -15 -3 -17 -20 -2 20 2 1...
output:
4 4 3 4 3 4 4 4 4 4 3 4 3 4 3 3 4 3 3 4 3 4 3 3 4 4 4 4 4 3 3 4 3 4 3 4 4 4 4 4 3 4 4 4 3 4 4 4 4 4 4 4 4 3 4 4 4 4 4 3 3 3 4 4 4 4 4 3 3 4 3 4 4 4 4 3 4 4 3 4 3 4 3 4 4 4 4 4 4 3 4 3 4 4 4 4 3 4 4 4
result:
ok 100 numbers
Test #6:
score: 0
Accepted
time: 1ms
memory: 3736kb
input:
100 -1 -13 -13 -14 -8 -1 -3 15 6 -14 19 -1 -16 -20 -14 -16 12 18 20 17 -19 17 -6 16 13 15 -8 18 16 10 17 20 0 0 -13 -19 -19 15 -14 -14 -11 -16 17 17 18 0 2 -10 20 -5 -8 -16 0 3 12 -19 0 -3 1 -14 -18 3 -12 -14 -15 20 1 17 20 -4 -20 6 20 20 -7 20 1 -9 -13 -4 2 17 -18 11 13 8 16 14 -12 16 -11 12 -20 0 ...
output:
3 4 4 4 3 4 4 4 3 4 4 4 3 4 3 4 3 4 3 3 4 4 3 3 3 4 4 4 3 3 4 4 4 3 4 4 4 4 3 3 4 4 4 4 4 4 3 4 4 3 3 3 4 3 3 4 4 4 3 4 4 3 3 3 3 4 4 4 4 3 3 3 4 4 3 4 3 3 4 3 3 4 3 4 4 3 3 3 4 4 3 3 4 3 3 3 3 3 4 3
result:
ok 100 numbers
Test #7:
score: 0
Accepted
time: 1ms
memory: 3780kb
input:
100 -16 0 17 16 16 16 -12 -16 14 12 19 -13 -20 -16 -8 -14 20 14 -6 -20 6 -19 12 18 -2 7 20 -19 3 -20 19 -5 12 -16 -12 -9 -11 0 19 4 11 -20 12 14 -14 -19 16 1 -12 -1 -8 -14 11 -15 2 9 -11 18 4 20 -14 3 -16 -20 -4 11 -16 7 -10 -11 20 16 -19 -10 8 -20 0 13 -17 -8 20 -17 2 14 -2 -17 13 7 -8 -11 -8 -6 -2...
output:
4 3 3 4 4 3 3 4 3 3 3 4 3 4 4 4 4 4 4 4 4 4 4 4 4 3 4 4 4 4 4 3 4 4 3 4 3 4 4 4 4 4 4 3 4 3 4 4 4 3 3 3 4 4 4 3 4 4 4 3 4 3 4 4 4 4 4 4 3 3 3 4 3 4 4 4 3 4 4 3 3 4 3 4 3 4 4 3 4 3 4 3 4 3 4 3 3 4 3 4
result:
ok 100 numbers
Test #8:
score: 0
Accepted
time: 0ms
memory: 3804kb
input:
1 1 -1 1 1 1 1 1 2 -1 1
output:
3
result:
ok 1 number(s): "3"
Test #9:
score: 0
Accepted
time: 1ms
memory: 3668kb
input:
100 20 19 -6 18 19 -19 -20 14 19 20 -1 19 -19 6 18 12 -20 19 18 19 4 0 -18 -19 10 -13 12 7 -8 11 -19 -18 -9 -19 -20 18 20 11 18 19 -19 19 8 18 -19 18 -19 -12 -19 20 11 12 9 -15 -2 -12 -12 -4 3 11 -19 9 -10 -18 3 -3 -19 4 20 11 -19 -20 10 -20 -19 17 20 -10 19 18 -17 -20 14 19 20 17 20 -6 -18 -19 9 -1...
output:
4 4 4 4 4 4 3 4 4 3 4 4 4 4 3 4 4 3 4 4 4 4 3 4 4 4 4 3 4 4 3 4 4 3 3 4 4 4 4 4 4 4 4 4 4 3 4 4 3 4 3 4 4 4 4 3 3 4 4 4 3 3 4 4 3 4 3 3 4 3 4 3 4 4 4 4 4 4 4 3 4 4 3 4 4 3 4 4 4 4 4 4 4 4 4 3 4 4 4 4
result:
ok 100 numbers
Test #10:
score: 0
Accepted
time: 1ms
memory: 3796kb
input:
100 13 -13 12 5 12 12 20 14 -14 -8 18 -17 -5 -1 -17 -10 9 9 -10 18 13 -17 -1 19 -18 11 1 -2 -17 -18 16 19 -17 -8 6 -14 -1 16 -18 6 4 -14 18 -10 14 13 3 12 -1 -14 -20 1 -11 12 15 20 4 -20 -7 -17 8 -19 1 -9 -10 -19 8 -4 -17 18 6 -14 -12 -12 -5 -12 6 19 -18 -11 -16 -16 -10 15 16 12 18 -9 -17 16 -18 5 -...
output:
4 4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 3 4 3 4 3 3 4 4 4 4 4 4 3 3 3 3 3 3 3 3 4 3 4 3 4 4 4 4 4 3 4 3 3 4 4 3 3 3 3 3 4 3 3 3 3 3 3 3 3 3 3 4 4 4 4 3 4 3 4 4 4 4 3 4 4 3 3 3 3 4 4 4 4 3 4 3 4 4 3 4 4 4 4 4
result:
ok 100 numbers
Test #11:
score: 0
Accepted
time: 1ms
memory: 3760kb
input:
73 14 -7 7 1 10 -16 -4 11 1 10 -14 -13 -16 1 -8 -6 -12 -10 -2 16 -5 -10 -12 0 -13 15 -10 0 0 -2 19 20 19 17 -9 -14 -20 -15 -20 6 3 19 4 -16 -1 5 -13 11 -16 -1 -19 -20 -17 0 11 -19 -20 -10 2 -3 -9 -15 -18 1 -13 17 -13 -11 1 -13 10 -20 17 8 -1 15 20 1 16 -2 -20 -18 8 0 -11 12 -18 17 0 -10 -4 0 10 9 0 ...
output:
2 2 2 4 2 2 2 2 2 2 2 2 2 4 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 2 2 2 3 2 2 2 2 2 4 2 2 2 2 2 2 4 3 4 2 2 2 2 2 4 3 2 2 2 4 2 2 2 2 2 4 2 2 3 2 2
result:
ok 73 numbers
Test #12:
score: -100
Wrong Answer
time: 1ms
memory: 3756kb
input:
100 -20 -20 10 -1 1 20 20 10 -1 6 15 -19 12 -17 20 -18 20 10 17 15 7 -19 0 -16 13 18 17 -10 11 15 17 13 9 -16 15 -6 -13 14 -13 -20 -19 2 13 -8 13 20 -13 -12 -19 -8 -20 20 4 -11 -11 20 -20 4 10 -10 -12 3 0 12 -17 -14 20 17 12 17 6 -19 7 -11 -20 14 8 -6 17 -13 -12 10 -2 19 20 15 -15 -9 -20 3 4 19 -19 ...
output:
3 3 4 3 3 3 4 3 3 4 3 3 3 3 3 4 3 4 4 4 3 3 3 4 3 4 3 3 4 4 3 3 4 3 3 3 3 3 3 3 4 3 4 4 3 3 3 4 4 3 3 3 4 3 4 4 3 3 4 4 3 4 3 3 4 3 3 4 3 3 3 3 4 3 3 4 4 4 3 4 3 3 4 3 3 3 3 3 4 3 4 3 3 4 4 4 3 4 4 3
result:
wrong answer 1st numbers differ - expected: '4', found: '3'