poj2653

Source Code

Problem: 2653 User: Praesidio
Memory: 3320K Time: 610MS
Language: C++ Result: Accepted
  • Source Code
    //poj 2653
    #include <cstdio>
    #include <cmath>
    #include <iostream>
    #include <vector>
    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;}
    bool operator == (const Point& a,const Point& b) {
    	return sgn(a.x-b.x)==0 && sgn(a.y-b.y)==0;
    }
    double cross(Point a,Point b,Point c){
    	return (b-a)*(c-a);
    }
    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;
    } 
    //==========
    struct Seg{
    	Point a,b;
    	Seg () {}
    	Seg (Point a,Point b) : a(a),b(b) {	}
    };
    Seg line[100002];
    int n;
    vector <int> ans;
    void init()
    {
    	for (int i=1;i<=n;i++) {
    		double x1,x2,y1,y2;
    		scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
    		line[i]=Seg(Point(x1,y1) , Point(x2,y2));
    	}
    }
    int main()
    {
    	while (~scanf("%d",&n)&&n) {
    		init();
    		ans.clear();
    		for (int i=n;i>=1;i--) {
    			int flag=1;
    			for (int j=i+1;j<=n;j++) {
    				Point p;
    				if (segcross(line[i].a,line[i].b,line[j].a,line[j].b,p)==1) {
    					flag=0;
    					break;
    				}
    			}
    			if (flag) ans.push_back(i);
    		}
    		printf("Top sticks:");
    		for (int i=ans.size()-1;i>0;i--) printf(" %d,",ans[i]);
    		printf(" %d.\n",ans[0]);
    	}
    	return 0;
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值