poj3304

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;
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值