meaning of the title
Given n line segments, it is determined whether there is a line, so that the projection of these n line segments on this line has a common point.
n<=100
Sol
A wonderful question.
We consider that if the projections of all line segments have coincident parts, then we can make a vertical line on the coincident part to pass through all points
At the same time, if we translate this line, it must coincide with a certain point.
Then consider rotation. It must intersect at the nearest point (the closest definition is that the angle with the smallest rotation intersects with it)
Then we come up with a \ (n^3 \) method: violently enumerate the lines formed by two points to determine whether they intersect with all points
Cross product can be used to judge the intersection of line and line segment
If the cross product of two points on the line segment and the line at the end of the line is the same sign, the line segment is on both sides of the line.
Otherwise, intersection
#include<cstdio> #include<cmath> #include<algorithm> using namespace std; const int MAXN = 1001; const double eps = 1e-10; int N; struct Point { double x, y; Point operator - (const Point &rhs) const { return {x - rhs.x, y - rhs.y}; } double operator ^ (const Point &rhs) const { return x * rhs.y - y * rhs.x; } bool operator == (const Point &rhs) const { return (x - rhs.x) < eps && (y -rhs.y) < eps; } }; struct L { Point a, b; }; Point line[MAXN][2]; int dcmp(double x) { if(fabs(x) < eps) return 0; return x > 0 ? 1 : -1; } bool judge(L l1, L l2) { Point tmp = l1.a - l1.b; bool flag = dcmp(dcmp(tmp ^ (l2.b - l1.b)) * dcmp(tmp ^ (l2.a - l1.b))) != 1; return flag; } bool check(Point a, Point b) { if(a == b) return 0; for(int i = 1; i <= N; i++) if(!judge({a, b}, {line[i][0], line[i][1]})) return 0; return 1; } void solve() { scanf("%d", &N); for(int i = 1; i <= N; i++) scanf("%lf %lf %lf %lf", &line[i][0].x, &line[i][0].y, &line[i][1].x, &line[i][1].y); for(int i = 1; i <= N; i++) for(int j = 0; j < 2; j++) for(int k = 1; k <= N; k++) for(int l = 0; l < 2; l++) if(check(line[i][j], line[k][l])) {puts("Yes!"); return ;} puts("No!"); } int main() { int T; scanf("%d", &T); for(; T; T--, solve()); }