Time Limit: 1000 MS Memory Limit: 65536 KB 64-bit integer IO format: %I64d , %I64u Java class name: Main
Description
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.
#include<cmath> #include<vector> #define eps 1e-8 int n; class { public: double x, y; Point(double x = 0, double y = 0) : x(x), y(y) {} Point operator+(Point a) { return Point(x + a.x, y + a.y); } Point operator-(Point a) { return Point(x - a.x, y - a.y); } };
classLine { public: Line() {} Line(Point a, Point b) : x(a), y(b) {} Point x, y; }; typedef Point Vector; typedef Line Segment; vector<Segment> p; doublecross(Vector a, Vector b){ return a.x * b.y - a.y * b.x; }
intis_clock(Point p0, Point p1, Point p2) { Vector a = p1 - p0; Vector b = p2 - p0; // printf("%.2f %.2fn", b.x, b.y); if (cross(a, b) < -eps) return1; if (cross(a, b) > eps) return2; return0; }
近期评论