Given n segments in the two dimensional space, write a program, which determines if there exists a line such that after projecting these segments on it, all projected segments have at least one point in common.
Input
Input begins with a number T showing the number of test cases and then, T test cases follow. Each test case begins with a line containing a positive integer n ≤ 100 showing the number of segments. After that, n lines containing four real numbers x1 y1 x2 y2 follow, in which (x1, y1) and (x2, y2) are the coordinates of the two endpoints for one of the segments.
Output
For each test case, your program must output “Yes!”, if a line with desired property exists and must output “No!” otherwise. You must assume that two floating point numbers a and b are equal if |a - b| < 10-8.
classPoint { public: double x, y; Point(double x = 0, double y = 0) : x(x), y(y) {} voidinput(){ scanf("%lf%lf", &x, &y); } booloperator<(const Point &a) const { return (!dcmp(x - a.x))? dcmp(y - a.y) < 0: x < a.x; } booloperator==(const Point &a) const { return dcmp(x - a.x) == 0 && dcmp(y - a.y) == 0; } db dis2(const Point a){ returnpow(x - a.x, 2) + pow(y - a.y, 2); } db dis(const Point a){ returnsqrt(dis2(a)); }
db dis2(){ return x * x + y * y; } db dis(){ returnsqrt(dis2()); } Point operator+(const Point a) { return Point(x + a.x, y + a.y); } Point operator-(const Point a) { return Point(x - a.x, y - a.y); } Point operator*(double p) { return Point(x * p, y * p); } Point operator/(double p) { return Point(x / p, y / p); } db dot(const Point a){ return x * a.x + y * a.y; } db cross(const Point a){ return x * a.y - y * a.x; } }; typedef Point Vector;