Source Code
Problem: 3304 | User: Praesidio | |
Memory: 184K | Time: 985MS | |
Language: C++ | Result: Accepted |
- Source Code
//poj3304 #include <cstdio> #include <cmath> using namespace std; #define sqr(x) ((x) * (x)) const double eps = 1e-8; int sgn(const double &a) {return (a > eps) - (a < -eps);} const double pi = acos(-1.0); struct Point{ double x,y; Point () {} Point (double x,double y) : x(x),y(y) {} }; typedef Point Vector; Vector operator - (Point A, Point B) {return Vector(A.x-B.x , A.y-B.y ); } bool operator < (const Point& a,const Point& b) { return a.x<b.x||(a.x==b.x && a.y < b.y ); } bool operator == (const Point& a,const Point& b) { return sgn(a.x-b.x)==0 && sgn(a.y-b.y)==0; } double operator ^ (Vector A, Vector B) {return A.x*B.x + A.y*B.y;} double operator * (Vector A, Vector B) {return A.x*B.y - A.y*B.x;} //--- struct Line{ Point a,b; Line () {} Line (Point a,Point b) : a(a) , b(b) { } }; int n; Line line[110]; Point point[220]; void init() { scanf("%d",&n); for (int i=1;i<=n;i++) { double x1,x2,y1,y2; scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2); line[i]=Line(Point(x1,y1) , Point(x2,y2)); point[2*i-1]=Point(x1,y1); point[2*i]=Point(x2,y2); } } int judge(Point a,Point b,Point c,Point d) { double d1=(b-a)*(c-a),d2=(b-a)*(d-a),d3=(d-c)*(a-c),d4=(d-c)*(b-c); if (( sgn(d1) ^ sgn(d2) )==-2 ) return 1; if ( d1==0 || d2==0 ) return 1; return 0; } bool solve() { for (int i=1;i<=2*n;i++) { for (int j=1;j<=2*n;j++) { if (point[i]==point[j]) continue; int flag=1; for (int l=1;l<=n;l++) { if (!judge(point[i],point[j],line[l].a,line[l].b)) flag=0; } if (flag) return true; } } return false; } int main() { int test; scanf("%d",&test); while (test--) { init(); // if (n==1||n==2) { // printf("Yes!\n"); // continue; // } if (solve()) printf("Yes!\n"); else printf("No!\n"); } return 0; }