QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#734223#4854. Viruscrimson231WA 2ms4416kbC++2315.3kb2024-11-11 06:59:422024-11-11 06:59:43

Judging History

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

  • [2024-11-11 06:59:43]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:4416kb
  • [2024-11-11 06:59:42]
  • 提交

answer

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cassert>
#include <vector>
#include <queue>
#include <deque>
#include <tuple>
typedef long long ll;
//typedef long double ld;
typedef double ld;
typedef std::pair<int, int> pi;
typedef std::vector<int> Vint;
typedef std::vector<ld> Vld;
const ld INF = 1e17;
const ld TOL = 1e-10;
const ld EPS = 1e-6;
const ld PI = acos(-1);
const int LEN = 1e3;
inline int sign(const ld& x) { return x < -TOL ? -1 : x > TOL; }
inline bool zero(const ld& x) { return !sign(x); }
inline ll sq(int x) { return (ll)x * x; }
inline ld norm(ld th) {
	while (th < 0) th += 2 * PI;
	while (sign(th - 2 * PI) >= 0) th -= 2 * PI;
	return th;
}
int gcd(int a, int b) { while (b) { int tmp = a % b; a = b; b = tmp; } return a; }
int gcd(int a, int b, int c) { int x = gcd(a, b); return gcd(x, c); }
int gcd(int a, int b, int c, int d) { a = std::abs(a); b = std::abs(b); c = std::abs(c); d = std::abs(d); int x = gcd(a, b, c); return gcd(x, c); }

int N, M, T, Q;
ld sc[4];
bool is_valid_number(const std::string& input) {
	size_t start = 0;
	// 첫 글자가 '-'이면 음수 가능하므로 넘어감
	if (input[start] == '-') {
		start++;
	}
	// 나머지 글자가 모두 숫자인지 확인
	for (size_t i = start; i < input.size(); ++i) {
		if (!std::isdigit(input[i])) {
			return false; // 숫자가 아닌 글자가 있으면 false 반환
		}
	}
	return true;
}
int make_int(const std::string& input) {
	size_t start = 0;
	int s = 1;
	int ret = 0;
	if (input[0] == '-' || (input[0] != '-' && !std::isdigit(input[0]))) start++, s = -1;
	for (size_t i = start; i < input.size(); ++i) {
		if (!std::isdigit(input[i])) continue;
		ret = ret * 10 + (input[i] - '0');
	}
	return ret * s;
}
struct Pos {
	ld x, y;
	Pos(ld X = 0, ld Y = 0) : x(X), y(Y) {}
	bool operator == (const Pos& p) const { return zero(x - p.x) && zero(y - p.y); }
	bool operator != (const Pos& p) const { return !zero(x - p.x) || !zero(y - p.y); }
	bool operator < (const Pos& p) const { return zero(x - p.x) ? y < p.y : x < p.x; }
	bool operator <= (const Pos& p) const { return *this < p || *this == p; }
	Pos operator + (const Pos& p) const { return { x + p.x, y + p.y }; }
	Pos operator - (const Pos& p) const { return { x - p.x, y - p.y }; }
	Pos operator * (const ld& scalar) const { return { x * scalar, y * scalar }; }
	Pos operator / (const ld& scalar) const { return { x / scalar, y / scalar }; }
	ld operator * (const Pos& p) const { return x * p.x + y * p.y; }
	ld operator / (const Pos& p) const { return x * p.y - y * p.x; }
	Pos operator ^ (const Pos& p) const { return { x * p.x, y * p.y }; }
	Pos& operator += (const Pos& p) { x += p.x; y += p.y; return *this; }
	Pos& operator -= (const Pos& p) { x -= p.x; y -= p.y; return *this; }
	Pos& operator *= (const ld& scale) { x *= scale; y *= scale; return *this; }
	Pos& operator /= (const ld& scale) { x /= scale; y /= scale; return *this; }
	Pos operator - () const { return { -x, -y }; }
	Pos operator ~ () const { return { -y, x }; }
	Pos operator ! () const { return { y, x }; }
	ld xy() const { return x * y; }
	Pos rot(ld the) { return { x * cos(the) - y * sin(the), x * sin(the) + y * cos(the) }; }
	ld Euc() const { return x * x + y * y; }
	ld mag() const { return sqrt(Euc()); }
	Pos unit() const { return *this / mag(); }
	ld rad() const { return atan2(y, x); }
	friend ld rad(const Pos& p1, const Pos& p2) { return atan2l(p1 / p2, p1 * p2); }
	int quad() const { return sign(y) == 1 || (sign(y) == 0 && sign(x) >= 0); }
	friend bool cmpq(const Pos& a, const Pos& b) { return (a.quad() != b.quad()) ? a.quad() < b.quad() : a / b > 0; }
	bool close(const Pos& p) const { return zero((*this - p).Euc()); }
	friend std::istream& operator >> (std::istream& is, Pos& p) { is >> p.x >> p.y; return is; }
	friend std::ostream& operator << (std::ostream& os, const Pos& p) { os << p.x << " " << p.y; return os; }
}; const Pos O = { 0, 0 };
typedef std::vector<Pos> Polygon;
ld cross(const Pos& d1, const Pos& d2, const Pos& d3) { return (d2 - d1) / (d3 - d2); }
ld cross(const Pos& d1, const Pos& d2, const Pos& d3, const Pos& d4) { return (d2 - d1) / (d4 - d3); }
int ccw(const Pos& d1, const Pos& d2, const Pos& d3) { return sign(cross(d1, d2, d3)); }
ld dot(const Pos& d1, const Pos& d2, const Pos& d3) { return (d2 - d1) * (d3 - d2); }
ld dot(const Pos& d1, const Pos& d2, const Pos& d3, const Pos& d4) { return (d2 - d1) * (d4 - d3); }
bool on_seg_strong(const Pos& d1, const Pos& d2, const Pos& d3) { return !ccw(d1, d2, d3) && sign(dot(d1, d3, d2)) >= 0; }
bool on_seg_weak(const Pos& d1, const Pos& d2, const Pos& d3) { return !ccw(d1, d2, d3) && sign(dot(d1, d3, d2)) > 0; }
ld area(const Polygon& H) {
	ld ret = 0;
	int sz = H.size();
	for (int i = 0; i < sz; i++) ret += H[i] / H[(i + 1) % sz];
	return ret * .5;
}
struct Linear {//ps[0] -> ps[1]
	Pos ps[2];
	Pos dir_;
	Pos& operator[](int i) { return ps[i]; }
	Pos dir() const { return dir_; }
	Linear(Pos a = Pos(0, 0), Pos b = Pos(0, 0)) {
		ps[0] = a;
		ps[1] = b;
		dir_ = (ps[1] - ps[0]).unit();
	}
	bool include(const Pos& p) const { return sign(dir_ / (p - ps[0])) > 0; }
	friend bool parallel(const Linear& l0, const Linear& l1) { return zero(l0.dir() / l1.dir()); }
	friend bool same_dir(const Linear& l0, const Linear& l1) { return parallel(l0, l1) && l0.dir() * l1.dir() > 0; }
	bool operator < (const Linear& l0) const {
		if (same_dir(*this, l0)) return l0.include(ps[0]);
		else return cmpq(this->dir(), l0.dir());
	}
};
typedef std::vector<Linear> Planes;
ld dist(const Pos& d1, const Pos& d2, const Pos& t) { return cross(d1, d2, t) / (d1 - d2).mag(); }
Pos intersection(const Pos& p1, const Pos& p2, const Pos& q1, const Pos& q2) { ld a1 = cross(q1, q2, p1), a2 = -cross(q1, q2, p2); return (p1 * a2 + p2 * a1) / (a1 + a2); }
Pos projection(const Pos& s1, const Pos& s2, const Pos& p) { return intersection(s1, s2, p, p + ~(s2 - s1)); }
Pos intersection(Linear& l1, Linear& l2) { return intersection(l1[0], l1[1], l2[0], l2[1]); }
std::vector<Pos> half_plane_intersection(std::vector<Linear>& HP) {
	auto check = [&](Linear& u, Linear& v, Linear& w) -> bool {
		return w.include(intersection(u, v));
		};
	std::sort(HP.begin(), HP.end());
	std::deque<Linear> dq;
	int sz = HP.size();
	for (int i = 0; i < sz; ++i) {
		if (i && same_dir(HP[i], HP[(i - 1) % sz])) continue;
		while (dq.size() > 1 && !check(dq[dq.size() - 2], dq[dq.size() - 1], HP[i])) dq.pop_back();
		while (dq.size() > 1 && !check(dq[1], dq[0], HP[i])) dq.pop_front();
		dq.push_back(HP[i]);
	}
	while (dq.size() > 2 && !check(dq[dq.size() - 2], dq[dq.size() - 1], dq[0])) dq.pop_back();
	while (dq.size() > 2 && !check(dq[1], dq[0], dq[dq.size() - 1])) dq.pop_front();
	sz = dq.size();
	if (sz < 3) return {};
	std::vector<Pos> HPI;
	for (int i = 0; i < sz; ++i) HPI.push_back(intersection(dq[i], dq[(i + 1) % sz]));
	return HPI;
}
Planes make_hp(const Polygon& H) {
	Planes V;
	int sz = H.size();
	for (int i = 0; i < sz; i++) V.push_back(Linear(H[i], H[(i + 1) % sz]));
	return V;
}
Pos centroid(const Polygon& H) {
	Pos cen = Pos(0, 0);
	ld A = 0;
	int sz = H.size();
	for (int i = 0; i < sz; i++) {
		ld a = H[i] / H[(i + 1) % sz];
		cen += (H[i] + H[(i + 1) % sz]) * a;
		A += a;
	}
	A *= .5;
	cen /= 6;
	if (!zero(A)) cen /= A;
	return cen;
}
struct Pos3D {
	ld x, y, z;
	Pos3D(ld X = 0, ld Y = 0, ld Z = 0) : x(X), y(Y), z(Z) {}
	bool operator == (const Pos3D& p) const { return zero(x - p.x) && zero(y - p.y) && zero(z - p.z); }
	bool operator != (const Pos3D& p) const { return !zero(x - p.x) || !zero(y - p.y) || !zero(z - p.z); }
	bool operator < (const Pos3D& p) const { return zero(x - p.x) ? zero(y - p.y) ? z < p.z : y < p.y : x < p.x; }
	ld operator * (const Pos3D& p) const { return x * p.x + y * p.y + z * p.z; }
	Pos3D operator / (const Pos3D& p) const {
		Pos3D ret;
		ret.x = y * p.z - z * p.y;
		ret.y = z * p.x - x * p.z;
		ret.z = x * p.y - y * p.x;
		return ret;
	}
	Pos3D operator + (const Pos3D& p) const { return { x + p.x, y + p.y, z + p.z }; }
	Pos3D operator - (const Pos3D& p) const { return { x - p.x, y - p.y, z - p.z }; }
	Pos3D& operator += (const Pos3D& p) { x += p.x; y += p.y; z += p.z; return *this; }
	Pos3D& operator -= (const Pos3D& p) { x -= p.x; y -= p.y; z -= p.z; return *this; }
	Pos3D operator * (const ld& n) const { return { x * n, y * n, z * n }; }
	Pos3D operator / (const ld& n) const { return { x / n, y / n, z / n }; }
	Pos3D& operator *= (const ld& n) { x *= n; y *= n; z *= n; return *this; }
	ld Euc() const { return x * x + y * y + z * z; }
	ld mag() const { return sqrtl(Euc()); }
	Pos3D unit() const { return *this / mag(); }
	Pos3D norm(const Pos3D& p) const { return (*this / p).unit(); }
	friend std::istream& operator >> (std::istream& is, Pos3D& p) { is >> p.x >> p.y >> p.z; return is; }
	friend std::ostream& operator << (std::ostream& os, const Pos3D& p) { os << p.x << " " << p.y << " " << p.z; return os; }
};
const Pos3D O3D = { 0, 0, 0 };
const Pos3D X_axis = { 1, 0, 0 };
const Pos3D Y_axis = { 0, 1, 0 };
const Pos3D Z_axis = { 0, 0, 1 };
const Pos3D INVAL3D = { INF, INF, INF };
typedef std::vector<Pos3D> Polygon3D;
typedef std::vector<Polygon3D> Polyhedron;
struct Line3D {
	Pos3D dir, p0;
	Line3D(Pos3D DIR = Pos3D(0, 0, 0), Pos3D P0 = Pos3D(0, 0, 0)) : dir(DIR), p0(P0) {}
};
struct Plane {
	ld a, b, c, d;
	Plane(ld A = 0, ld B = 0, ld C = 0, ld D = 0) : a(A), b(B), c(C), d(D) {}
	Plane& operator *= (const ld& s) { a *= s; b *= s; c *= s; d *= s; return *this; }
	Pos3D norm() const { return Pos3D(a, b, c); };
	Plane operator + (const ld& n) const { return { a, b, c, d + n }; }
	Plane operator - (const ld& n) const { return { a, b, c, d - n }; }
	Plane& operator += (const ld& n) { d += n; return *this; }
	Plane& operator -= (const ld& n) { d -= n; return *this; }
	friend std::istream& operator >> (std::istream& is, Plane& f) { is >> f.a >> f.b >> f.c >> f.d; return is; }
	friend std::ostream& operator << (std::ostream& os, const Plane& f) { os << f.a << " " << f.b << " " << f.c << " " << f.d; return os; }
} knife;
typedef std::vector<Plane> Surfaces;
void update_sc(const Plane& p) {
	ld angle1 = -atan2(p.b, p.a);
	ld dx = sqrtl(p.a * p.a + p.b * p.b);
	ld angle2 = -atan2(dx, p.c);
	sc[0] = sin(angle1);
	sc[1] = cos(angle1);
	sc[2] = sin(angle2);
	sc[3] = cos(angle2);
	return;
}
Pos3D rotate(const Pos3D& p) {
	ld x = p.x * sc[1] - p.y * sc[0], y = p.x * sc[0] + p.y * sc[1], z = p.z;
	return Pos3D(z * sc[2] + x * sc[3], y, z * sc[3] - x * sc[2]);
}
Pos convert(Pos3D p, const Pos3D& v) {
	p -= v;
	p = rotate(p);
	return Pos(p.x, p.y);
}
Pos3D recover(const Pos& p2D, const Pos3D& v) {
	ld x = p2D.x * -sc[3];
	ld y = p2D.y;
	ld z = p2D.x * sc[2];
	Pos3D p = Pos3D(x * -sc[1] + y * sc[0], x * sc[0] + y * sc[1], z);
	return p + v;
}
typedef std::vector<Pos3D> Polygon3D;
typedef std::vector<Polygon3D> Polyhedron;
Pos3D cross(const Pos3D& d1, const Pos3D& d2, const Pos3D& d3) { return (d2 - d1) / (d3 - d2); }
ld dot(const Pos3D& d1, const Pos3D& d2, const Pos3D& d3) { return (d2 - d1) * (d3 - d2); }
int ccw(const Pos3D& d1, const Pos3D& d2, const Pos3D& d3, const Pos3D& norm) { return sign(cross(d1, d2, d3) * norm); }
bool on_seg_strong(const Pos3D& d1, const Pos3D& d2, const Pos3D& d3) { return zero(cross(d1, d2, d3).mag()) && sign(dot(d1, d3, d2)) >= 0; }
bool on_seg_weak(const Pos3D& d1, const Pos3D& d2, const Pos3D& d3) { return zero(cross(d1, d2, d3).mag()) && sign(dot(d1, d3, d2)) > 0; }
Line3D L(const Pos3D& p1, const Pos3D& p2) { return { p2 - p1, p1 }; }
ld dist(const Plane& s, const Pos3D& p) { return (s.norm() * p + s.d) / s.norm().mag(); }
Pos3D offset(const Plane& s, const Pos3D& p) { ld d = dist(s, p); return s.norm().unit() * -d; }
Pos3D intersection(const Plane& S, const Line3D& l) {
	ld det = S.norm() * l.dir;
	if (zero(det)) return { INF, INF, INF };
	ld t = -((S.norm() * l.p0 + S.d) / det);
	return l.p0 + (l.dir * t);
}
Pos3D intersection(const Plane& S, const Pos3D& p1, const Pos3D& p2, const bool& f = 0) {
	Line3D l = L(p1, p2);
	Pos3D inx = intersection(S, l);
	if (f && !on_seg_strong(p1, p2, inx)) return { INF, INF, INF };
	return inx;
}
int intersection(const Plane& p1, const Plane& p2, Line3D& l) {
	Pos3D n1 = p1.norm();
	Pos3D n2 = p2.norm();
	Pos3D dir = n2 / n1;
	dir = dir.unit();
	if (zero(dir.mag())) {
		ld f = n1 * n2;
		ld d1 = dist(p1, O3D);
		ld d2 = dist(p2, O3D);
		if (sign(f) > 0) return sign(d2 - d1) >= 0 ? 0 : -1;
		else return sign(d2 + d1) >= 0 ? 0 : -2;
	}
	Pos3D q1 = intersection(p1, Line3D(n1, O3D));
	Pos3D v1 = n1 / dir;
	Pos3D p0 = intersection(p2, Line3D(v1, q1));
	l = Line3D(dir, p0);
	return 1;
}
int A_[LEN], B_[LEN], C_[LEN], D_[LEN];
bool V[LEN];
void solve() {
	std::cin.tie(0)->sync_with_stdio(0);
	std::cout.tie(0);
	std::cout << std::fixed;
	std::cout.precision(15);
	std::cin >> N;
	Surfaces S(N);
	int ii = 0;
	for (Plane& p : S) {
		int a, b, c, d;
		std::string w, x, y, z;
		std::cin >> w >> x >> y >> z;
		assert(is_valid_number(w));
		a = make_int(w);
		assert(is_valid_number(x));
		b = make_int(x);
		assert(is_valid_number(y));
		c = make_int(y);
		assert(is_valid_number(z));
		d = make_int(z);
		//std::cin >> a >> b >> c >> d;
		A_[ii] = a; B_[ii] = b; C_[ii] = c; D_[ii] = d;
		int g = gcd(a, b, c, d);
		a /= g; b /= g; c /= g; d /= g;
		ii++;
		a *= -1; b *= -1; c *= -1;
		p = Plane(a, b, c, d);
		p += EPS;
	}
	ld bnd = 1e7;
	Pos p1 = Pos(-bnd, -bnd),
		p2 = Pos(bnd, -bnd),
		p3 = Pos(bnd, bnd),
		p4 = Pos(-bnd, bnd);
	Planes B = {
		Linear(p1, p2),
		Linear(p2, p3),
		Linear(p3, p4),
		Linear(p4, p1)
	};
	Pos3D q;
	bool f0 = 0;
	for (int i = 0; i < N; i++) {
		update_sc(S[i]);
		Pos3D v = offset(S[i], O3D);
		Line3D l;
		int f = 1;
		Planes hp = B;
		memset(V, 0, sizeof V);
		for (int j = 0; j < N; j++) {
			if (i == j) continue;
			f = intersection(S[i], S[j], l);
			if (f == -2) { std::cout << "banana\n"; return; }
			if (f == -1) break;
			if (f == 0) continue;
			Pos s = convert(l.p0, v);
			Pos e = convert(l.p0 + l.dir, v);
			hp.push_back(Linear(s, e));
		}
		if (f == -1) continue;
		Polygon hpi = half_plane_intersection(hp);
		if (!hpi.size()) continue;
		int k = 0;
		for (int j = 0; j < N; j++) {
			if (i == j || !V[j]) continue;
			if (!k) {
				f = intersection(S[i], S[j], l);
				k = 1;
				//std::cout << "fffffff::" << f << "\n";
				break;
			}
			else if (k) {
				ld ff = S[j].norm() * l.dir;
				if (zero(ff)) continue;
				Pos3D inx = intersection(S[j], l);
				Pos3D v = l.p0 - inx;
				if (ff > 0 && v * l.dir > 0) l.p0 = inx;
				else if (ff < 0 && v * l.dir < 0) l.p0 = inx;
			}
		}
		Pos cen = centroid(hpi);
		q = recover(cen, v);
		//l = { S[i].norm(), q };
		//q = intersection(S[i], l);
		//q = recover(hpi[0], v);
		f0 = 1;
		for (int i = 0; i < ii; i++) {
			ld dd = (A_[i] * q.x + B_[i] * q.y + C_[i] * q.z - 0.001);
			if (D_[i] < dd) { f0 = 0; break; }
		}
		if (!f0) continue;
		break;
	}
	if (f0) {
		for (int i = 0; i < ii; i++) {
			//std::cout << D_[i] - (A_[i] * q.x + B_[i] * q.y + C_[i] * q.z - 0.001) << "\n";
			ld dd = (A_[i] * q.x + B_[i] * q.y + C_[i] * q.z - 0.001);
			assert(D_[i] > dd);
			//std::cout << D_[i] - dd << "\n";
		}
		std::cout << q << "\n";
	}
	else std::cout << "banana\n";
	return;
}
int main() { solve(); return 0; }//boj14118 Virus

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 4276kb

input:

10
344 -792 -688 515
-271 653 -152 715
-320 -275 -324 -283
-182 142 -387 -584
75 406 -424 868
-139 -647 54 150
-981 -401 -734 -202
-858 555 -884 954
-94 891 -557 457
-216 -281 -743 -916

output:

7306288.606684352271259 -92948.908225375605980 3760142.883741143625230

result:

ok correct

Test #2:

score: 0
Accepted
time: 0ms
memory: 4340kb

input:

100
733 991 -342 -694
328 446 -154 -351
-631 -850 290 334
694 942 -326 540
439 599 -207 -299
-552 -729 249 -667
728 984 -343 -920
341 459 -159 955
-342 -455 154 -307
-595 -793 269 834
687 944 -326 -420
-688 -911 310 866
538 740 -257 -928
708 964 -337 358
574 789 -273 44
490 670 -235 -408
-387 -518 1...

output:

1216569.303690147818998 1316871.017261026194319 6423289.975761856883764

result:

ok correct

Test #3:

score: 0
Accepted
time: 0ms
memory: 4416kb

input:

100
-153 53 -16 -823
-232 185 -29 -929
120 -120 13 811
-268 268 -36 -963
76 -79 9 536
-218 206 -22 -705
-136 117 -16 -439
-316 300 -36 -978
-287 308 -36 -857
-207 250 -28 -591
-318 253 -33 -959
-301 353 -42 -857
-201 153 -21 -599
-310 393 -37 -813
-334 224 -36 -994
-313 323 -37 -835
-289 338 -41 -75...

output:

0.662125371960207 0.643383798712172 47.237134901364549

result:

ok correct

Test #4:

score: -100
Wrong Answer
time: 2ms
memory: 4028kb

input:

99
-384 -136 880 952
-367 -107 887 749
-332 -44 908 308
-285 -28 799 196
-266 -127 544 889
-266 -101 596 707
-265 -88 619 616
-253 -6 747 42
-249 -135 477 945
-244 -14 704 98
-242 -25 676 175
-239 -14 689 98
-236 -97 514 679
-198 -88 418 616
-190 56 682 -392
-188 111 786 -777
-184 130 812 -910
-178 ...

output:

banana

result:

wrong output format Expected double, but "banana" found