Segments
Time Limit: 1000MS |
|
Memory Limit: 65536K |
Total Submissions: 12161 |
|
Accepted: 3847 |
Description
Given n segments in the dimensional space, write a program, which determines if there exists a line such that After projecting these segments on it, all projected segments has 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 then, n lines containing four real numbers x1 y1 x2 y2 follow, in which (x1, y1) and (x2, y2) is the coordinates of the endpoints for one of the SEG ments.
Output
For each test case, the your program must output "yes!", if a line with the desired property exists and must output "no!" Otherwis E. You must assume, floating point numbers a and b is equal if | a - b| < 10-8.
Sample Input
321.0 2.0 3.0 4.04.0 5.0 6.0 7.030.0 0.0 0.0 1.00.0 1.0 0.0 2.01.0 1.0 2.0 1.030.0 0.0 0.0 1.00.0 2.0 0.0 3.01.0 1.0 2.0 1 .0
Sample Output
yes! yes! No!
/*POJ 3304 lines intersect with line segments to give you n lines, to determine if there is a line, they have a common point when projecting to the top if there is a line like this, then all the line segments can intersect a straight line to rotate the line a certain way, Must intersect with at least two of the endpoints of all the lines, so enumerate all the endpoints and judge them//pay attention to the same points hhh-2016-05-04 20:48:26*/#include <iostream> #include <vector > #include <cstring> #include <string> #include <cstdio> #include <queue> #include <cmath > #include <algorithm> #include <functional> #include <map>using namespace std; #define Lson (i< <1) #define Rson ((i<<1) | |) typedef LONG LONG ll;const int MAXN = 40010;double eps = 1e-8;int tot;int n,m;double X1,x2,y1,y2;int SGN (double x) {if (Fabs (x) < EPS) return 0; if (x < 0) return-1; else return 1;} struct point{double x, y; Point () {}, point (double _x,double _y) {x = _x,y = _y; } Point operator-(const point &b) const {return point (X-B.X,Y-B.Y); } double operator ^ (const point &b) const {return x*b.y-y*b.x; }};struct line{Point s,t; Line () {}Line (point _s,point _t) {s = _s; t = _t; }};int TANS[MAXN]; Line LINE[MAXN]; Point PO[MAXN]; Point P;bool seg_inter_line (line l1,line L2) {return sgn ((l2.s-l1.t) ^ (l1.s-l1.t)) *SGN ((l2.t-l1.t) ^ (l1.s-l1.t)) <= 0;} BOOL Cal (line TL) {for (int i = 0;i < n;i++) {if (!seg_inter_line (Tl,line[i])) {return F Alse; }} return true; int main () {int T; scanf ("%d", &t); while (t--) {scanf ("%d", &n); int flag = 0; tot = 0; if (n < 3) flag = 1; for (int i = 0; i < n; i++) {scanf ("%lf%lf%lf%lf", &x1,&y1,&x2,&y2); po[tot++] = point (X1,Y1); po[tot++] = point (X2,Y2); Line[i] = line (po[tot-1],po[tot-2]); } for (int i = 0, i < tot &&!flag; i++) {for (int j = i+1;!flag && J < tot ; J + +) {if (po[i].x = = po[j].x && po[i].y = = po[j].y) continue; if (Cal (line (PO[I],PO[J))) {flag = 1; Break }}} if (flag) printf ("yes!\n"); else printf ("no!\n"); } return 0;}
POJ 3304 line intersects the line segment