poj1969

Source Code

Problem: 1696 User: Praesidio
Memory: 188K Time: 0MS
Language: C++ Result: Accepted
  • Source Code
    //poj1696
    #include <iostream>
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <algorithm>
    using namespace std;
    #define sqr(x) ((x)*(x))
    const double eps = 1e-9;
    const double pi = acos(-1.0);
    int sgn (const double &x) { return (x>eps) - (x< -eps); }
    struct Point {
    	int id;
    	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 == (Point A,Point B) {
    	return sgn(A.x-B.x)==0 && sgn(A.y-B.y)==0 ; 
    }
    
    struct Line {
    	Point p;
    	Point q;
    	Vector v;
    	double ang;
    	double ang2;
    	Line () {}
    	Line (Point p,Point q) : p(p),q(q) {
    		v = q-p;
    		ang = atan2 (v.y , v.x);
    		if (sgn(ang)==-1) ang += 2*pi;	
    	}
    	bool operator < (const Line& L) const {
    		return ang<L.ang;
    	} 
    };
    
    int n;
    Point point[55];
    Line line[55];
    int vis[55];
    
    void init()
    {
    	scanf("%d",&n);
    	for (int i=0;i<n;i++) {
    		scanf("%d%lf%lf",&point[i].id,&point[i].x,&point[i].y);
    	}
    }
    bool cmp(Point A,Point B) {
    	return (A.y != B.y)? A.y<B.y : A.x<B.x ;
    }
    int main()
    {
    	int test;
    	scanf("%d",&test);
    	while (test--) {
    		init();
    		sort (point,point+n,cmp);
    		printf("%d ",n);
    		Point pole = point[0];
    		memset(vis,0,sizeof(vis));
    		int tmp=n-1;
    		double angle=0;
    		printf("%d",pole.id);
    		while (tmp--) {
    
    			vis[pole.id]=1;
    			int top=0;
    			
    			for (int i=0;i<n;i++) {
    				if (vis[point[i].id]) continue;
    				line[top] = Line ( pole , point[i] );
    				line[top].ang2 = line[top].ang;
    				line[top].ang -= angle;
    				if (sgn(line[top].ang)==-1) line[top].ang += 2*pi;
    				top++;
    			}
    						
    			sort(line,line+top);
    
    			pole = line[0].q;
    			angle= line[0].ang2 ;
    			
    			printf(" %d",pole.id);
    		}
    		printf("\n");
    	}
    	return 0;
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值