QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#617802#9227. Henry the Plumberucup-team5062#WA 1ms3724kbC++172.5kb2024-10-06 17:11:072024-10-06 17:11:07

Judging History

你现在查看的是最新测评结果

  • [2024-10-06 17:11:07]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3724kb
  • [2024-10-06 17:11:07]
  • 提交

answer

#include <cmath>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

const long double EPS = 1.0e-8;

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 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 exceptional cases
	if ((p3 - p1).dot(p2) == 0 && (p1 - p3).cross(p4) == 0) {
		return false;
	}
	if ((p3 - p1).cross(p2) == 0 && (p1 - p3).dot(p4) == 0) {
		return false;
	}

	// check for non-parallel case
	auto sqr = [&](long double x) -> long double {
		return x * x;
	};
	point z = cross_point(p1, p1 + p2, p3, p3 + p4);
	point m = (p1 + p3) / 2;
	long double r = sqrt(sqr(p3.x - p1.x) + sqr(p3.y - p1.y) + sqr(z3 - z1)) / 2;
	return (z - m).abs() <= r + 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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3664kb

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: 3724kb

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
3
4
4
4
4
3
4
4
4
4
3
4
4
4
4
4
4
3
4
4
3
4
4
4
3
4
4
4
4
3
4
4
4
4
4
4
4
3
4
4
3
4
4
4
3
3
3
4
4
3
4
4
4
4
4
4
4
3
4
3
4
3
4
3
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
3
4
4
4
4
4
4
4
4
4
3
4
4
4
3

result:

wrong answer 6th numbers differ - expected: '4', found: '3'