Test instructions: There are n lines, ask if there is a straight line so that the projection of all segments in this line has at least one thing in common.
Thinking: Reverse thinking, it is obvious that this problem can be translated into whether there is a straight line through all segments, if so, the problem requires a straight line and the line is perpendicular, and the common point is perpendicular.
Therefore, you only need to enumerate the lines formed by each of the two endpoints to determine if they intersect all segments. proves that, if there is a line L that intersects all the segments, I can pan until it does not meet the "intersect with all segments" condition, when l passes through one end of a segment, and then rotates the l until it does not meet the "intersect with all segments" condition, it must intersect with the other endpoint.
To determine the intersection of a line and a segment can be used
1, the cross product nature, if the line segment and the straight line intersection, then the line segment two ends in the line two sides, sets T1 as one end and the straight line cross product, T2 is the other end and the line cross product, the line segment and the straight line intersection, T1 X t2<=0
2, the line line is TMP, the intersection of L and TMP p, if the distance between the ends of the segment and the sum equal to the length of the segment, then the line segment intersects with the line
Pit point:
1,n=1 need a special sentence.
2, when the two selected points coincide, it causes all points to have a cross product of the line that is less than 0 and thus considers each segment to intersect the line.
#include <stdio.h>#include<string.h>#include<math.h>structpoint{Doublex, y; Point () {}, point (DoubleX_Doubley_) {x=x_,y=Y_; } Pointoperator-(ConstPoint &b)Const{ returnPoint (x-b.x,y-b.y); } Double operator*(ConstPoint &b)Const{//dot Product returnx*b.x+y*b.y; } Double operator^(ConstPoint &b)Const{//Cross Product returnx*b.y-y*b.x; }};DoubleCal (Point p0,point p1,point p2) {//less than 0 means left-folded at P1, greater than 0 right-fold, equals 0-line return(p1-p0) ^ (p2-p0);}Const intn=111;Const Doubleesp=1e-8;p oint s[n],e[n];intN;intPD (Point A,point b) {if(Fabs (a.x-b.x) <esp&&fabs (A.Y-B.Y) <ESP)return 0; for(intI=1; i<=n;i++){ if(Cal (S[i],a,b) *cal (e[i],a,b) >ESP)return 0; } return 1;}intMain () {intt,i,j; scanf ("%d",&t); while(t--) {scanf ("%d",&N); for(i=1; i<=n;i++) {scanf ("%LF%LF%LF%LF",&s[i].x,&s[i].y,&e[i].x,&e[i].y); } intf=0; if(n<2) f=1; for(i=1; i<=n&&!f;i++){ for(j=i+1; j<=n&&!f;j++){ if(PD (S[i],s[j])) f=1; if(PD (S[i],e[j])) f=1; if(PD (E[i],s[j])) f=1; if(PD (E[i],e[j])) f=1; } } if(f) Puts ("yes!"); ElsePuts"no!"); } return 0;}
Http://blog.sina.com.cn/s/blog_6635898a0100n2lv.html
Http://www.cnblogs.com/staginner/archive/2012/02/07/2340835.html
POJ 3304 Segments "cross Product"