poj1410

Source Code

Problem: 1410 User: Praesidio
Memory: 180K Time: 0MS
Language: C++ Result: Accepted
  • Source Code
    //poj 1410
    #include <cstdio>
    #include <cmath>
    using namespace std;
    #define sqr(x) ((x)*(x))
    const double eps = 1e-9;
    const double pi = acos(-1.0);
    int sgn(const double &a) {return (a > eps) - (a < -eps);}
    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 ); }
    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; }
    double len (Point a,Point b) {
    	return sqrt(sqr(a.x-b.x)+sqr(a.y-b.y));
    }
    double cross(Point a,Point b,Point c){
    	return (b-a)*(c-a);
    }
    bool operator == (const Point& a,const Point& b) {
    	return sgn(a.x-b.x)==0 && sgn(a.y-b.y)==0;
    }
    int betweenCmp(Point a,Point b,Point c) {
    	return sgn( (b-a) ^ (c-a) );
    }
    int segcross(Point a,Point b,Point c,Point d,Point& p)
    {
    	double s1=cross(a,b,c),s2=cross(a,b,d),s3=cross(c,d,a),s4=cross(c,d,b);
    	int d1=sgn(s1),d2=sgn(s2),d3=sgn(s3),d4=sgn(s4);
    	if ( (d1^d2)==-2 && (d3^d4)==-2 ) {
    		p.x = (c.x*s2 - d.x*s1) / (s2-s1) ; 
    		p.y = (c.y*s2 - d.y*s1) / (s2-s1) ;
    		return 1;
    	}
    	if (d1==0 && betweenCmp(c,a,b)<=0 ||
    		d2==0 && betweenCmp(d,a,b)<=0 ||
    		d3==0 && betweenCmp(a,c,d)<=0 ||
    		d4==0 && betweenCmp(b,c,d)<=0 )
    		return 2;
    	return 0;
    } 
    //=====
    double max(double a,double b){
    	return (a>b)?a:b;
    }
    double min(double a,double b){
    	return (a<b)?a:b;
    }
    struct Seg{
    	Point a,b;
    	Seg () {	}
    	Seg ( Point a ,Point b) : a(a),b(b) {	}
    };
    Seg line[5];
    int n;
    int main()
    {
    //	freopen("a.in","r",stdin);
    //	freopen("a.out","w",stdout);
    	scanf("%d",&n);
    	while (n--) {
    		double x1,x2,y1,y2;
    		scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
    		Point a=Point (x1,y1);
    		Point b=Point (x2,y2);
    		scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
    		if (x1>x2) {
    			double tmp;
    			tmp = x1; x1 = x2; x2 = tmp;
    		}
    		if (y1<y2) {
    			double tmp;
    			tmp = y1; y1 = y2; y2 = tmp;
    		}
    		line[1]=Seg( Point (x1,y1) , Point (x1,y2) );
    		line[2]=Seg( Point (x1,y1) , Point (x2,y1) );
    		line[3]=Seg( Point (x2,y2) , Point (x2,y1) );
    		line[4]=Seg( Point (x2,y2) , Point (x1,y2) );
    		int flag=0;
    
    		for (int i=1;i<=4;i++) {
    			Point p;
    			if ( segcross( a , b , line[i].a , line[i].b ,p) != 0) {
    				flag=1;
    				break;
    			}
    		}
    		if (flag) printf("T\n");
    		else {
    			if (x1<min(a.x,b.x)&&x2>min(a.x,b.x)&&y1>max(a.y,b.y)&&y2<min(a.y,b.y)) 
    				printf("T\n");
    			else printf("F\n");
    		}
    		
    	}
    	
    	return 0;
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值