QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#295572#5. 在线 O(1) 逆元zzuqyCompile Error//C++142.7kb2023-12-31 14:30:032023-12-31 14:30:04

Judging History

你现在查看的是测评时间为 2023-12-31 14:30:04 的历史记录

  • [2024-11-05 21:57:25]
  • 管理员手动重测本题所有提交记录
  • [2023-12-31 14:30:04]
  • 评测
  • [2023-12-31 14:30:03]
  • 提交

answer

#include <bits/stdc++.h>
#define EPS 1e-9

struct Vector {
	double x, y;
	inline Vector() {

	}
	inline Vector(double x, double y) {
		this->x = x;
		this->y = y;
	}
	inline Vector operator + (const Vector &a)const {
		return (Vector) {
			x + a.x, y + a.y
		};
	}
	inline Vector operator - (const Vector &a)const {
		return (Vector) {
			x - a.x, y - a.y
		};
	}
	inline Vector operator * (const double &a)const {
		return (Vector) {
			x *a, y *a
		};
	}
	inline Vector operator / (const double &a)const {
		return (Vector) {
			x / a, y / a
		};
	}
	inline double operator * (const Vector &a)const {
		return x * a.x + y * a.y;
	}
	inline double operator ^ (const Vector &a)const {
		return x * a.y - y * a.x;
	}
};

struct Line {
	Vector way, o;
	inline Line( Vector a,  Vector b) {
		o = a;
		way = b - a;
	}
};

inline Vector getIntersection( Line a, Line b) {
	if ((a.way ^ b.way) == 0) {
		return (Vector) {
			1e10, 1e10
		};
	}
	double x = (b.way ^ (a.o - b.o)) / (a.way ^ b.way);
	return a.o + a.way * x;
}

inline Vector getIntersection(Vector a, Vector b, Vector c, Vector d) {
	return getIntersection((Line) {
		b - a, a
	}, (Line) {
		d - c, c
	});
}

inline int in(double x, double a, double b) {
	return x >= std::min(a, b) - EPS && x <= std::max(a, b) + EPS;
}

inline int check(Vector a, Vector b, Vector c, Vector d) {
	Vector o(0, 0);
	o = getIntersection(a, b, c, d);
	if (o.x > 1e9) {
		return 0;
	}
	printf("%lf %lf\n", o.x, o.y);
	printf("%d%d%d%d\n", in(o.x, a.x, b.x), in(o.x, c.x, d.x), in(o.y, a.y, b.y), in(o.y, c.y, d.y));
	return !(in(o.x, a.x, b.x) && in(o.x, c.x, d.x) && in(o.y, a.y, b.y) && in(o.y, c.y, d.y));
}

int main() {
	int $;
	scanf("%d", &$);
	while ($--) {
		Vector a;
		Vector b;
		Vector c1;
		Vector c2;
		Vector d1;
		Vector d2;
		scanf("%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf", &a.x, &a.y, &b.x, &b.y, &c1.x, &c1.y, &c2.x, &c2.y, &d1.x, &d1.y, &d2.x,
		      &d2.y);
		if (check(a, b, c1, c2) && check(a, b, d1, d2)) {
			puts("0");
		} else if (check(c1, c2, d1, d2)) {
			puts("1");
		} else {
			Vector a0(0, 0), a1(0, 0);
			Vector b0(0, 0), b1(0, 0);
			if (check(a, c1, d1, d2)) {
				a0 = c1;
			} else {
				a0 = c2;
			}
			if (check(a, d1, c1, c2)) {
				a1 = d1;
			} else {
				a1 = d2;
			}
			if (check(b, c1, d1, d2)) {
				b0 = c1;
			} else {
				b0 = c2;
			}
			if (check(b, d1, c1, c2)) {
				b1 = d1;
			} else {
				b1 = d2;
			}
			Vector o(0, 0), oo(0, 0);
			o = getIntersection(a, a0, b, b1);
			oo = getIntersection(a, a1, b, b0);
			if ((a0.y > a.y) == (o.y > a.y) || (a1.y > a.y) == (oo.y > a.y)) {
				puts("1");
			} else {
				puts("2");
			}
		}
	}
	return 0;
}

詳細信息

implementer.cpp: In function ‘int main()’:
implementer.cpp:22:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   22 |         scanf("%d", &n);
      |         ~~~~~^~~~~~~~~~
answer.code: In function ‘int main()’:
answer.code:84:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   84 |         scanf("%d", &$);
      |         ~~~~~^~~~~~~~~~
answer.code:92:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   92 |                 scanf("%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf", &a.x, &a.y, &b.x, &b.y, &c1.x, &c1.y, &c2.x, &c2.y, &d1.x, &d1.y, &d2.x,
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   93 |                       &d2.y);
      |                       ~~~~~~
/usr/bin/ld: /tmp/cciRyhhH.o: in function `main':
answer.code:(.text.startup+0x0): multiple definition of `main'; /tmp/ccvw13rH.o:implementer.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccvw13rH.o: in function `main':
implementer.cpp:(.text.startup+0x153): undefined reference to `init(int)'
/usr/bin/ld: implementer.cpp:(.text.startup+0x1f8): undefined reference to `inv(int)'
collect2: error: ld returned 1 exit status