POJ 1696 Space Ant
来源:互联网 发布:淘宝旧版本5.9下载安装 编辑:程序博客网 时间:2024/05/21 08:54
点击打开链接
题目大意:
有M组样例
每组样例N个点
每个点为 编号 X Y
每天只能左转移动一点
求点的编号顺序
思路:
从x最小的点对应在y轴上的投影为起点
做卷包裹法不返回起点即可
每添加一点标记下
直到所有点都走完
#include <cmath>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const double eps=1e-7;//精度const int INF=1<<29;struct Point{double x,y;Point(double x=0,double y=0):x(x),y(y){}};typedef Point Vector;Vector operator+(Vector a,Vector b){return Vector(a.x+b.x,a.y+b.y);}//向量+向量=向量Vector operator-(Point a,Point b){return Vector(a.x-b.x,a.y-b.y);}//点-点=向量Vector operator*(Vector a,double p){return Vector(a.x*p,a.y*p);}//向量*实数=向量Vector operator/(Vector a,double p){return Vector(a.x/p,a.y/p);}//向量/实数=向量bool operator<(const Point&a,const Point&b){return a.x<b.x||(a.x==b.x&&a.y<b.y);}int doublecmp(double x){//判断double等于0或。。。if(fabs(x)<eps)return 0;else return x<0?-1:1;}bool operator==(const Point&a,const Point&b){return doublecmp(a.x-b.x)==0&&doublecmp(a.y-b.y)==0;}double Dot(Vector a,Vector b){return a.x*b.x+a.y*b.y;}//|a|*|b|*cosθ 点积double Length(Vector a){return sqrt(Dot(a,a));}//|a| 向量长度double Angle(Vector a,Vector b){return acos(Dot(a,b)/Length(a)/Length(b));}//向量夹角θdouble Cross(Vector a,Vector b){return a.x*b.y-a.y*b.x;}//叉积 向量围成的平行四边形的面积double Area2(Point a,Point b,Point c){return Cross(b-a,c-a);}//同上 参数为三个点Vector Rotate(Vector a,double rad){//向量旋转rad弧度return Vector(a.x*cos(rad)-a.y*sin(rad),a.x*sin(rad)+a.y*cos(rad));}Vector Normal(Vector a){//计算单位法线double L=Length(a);return Vector(-a.y/L,a.x/L);}Point GetLineProjection(Point p,Point a,Point b){Vector v=b-a;return a+v*(Dot(v,p-a)/Dot(v,v));}Point GetLineIntersection(Point p,Vector v,Point q,Vector w){//求直线交点 有唯一交点时可用Vector u=p-q;double t=Cross(w,u)/Cross(v,w);return p+v*t;}//直线P+tV//--------------------------------------int vis[55];struct node{int pos;Point p;bool friend operator<(node a,node b){return a.p<b.p;}}arr[55];int main(){int T;scanf("%d",&T);while(T--){int n;scanf("%d",&n);printf("%d",n);double star=INF;arr[0].pos=0;for(int i=1;i<=n;i++){arr[i].pos=0;scanf("%*d%lf%lf",&arr[i].p.x,&arr[i].p.y);star=min(star,arr[i].p.y);}arr[0].p.x=0;arr[0].p.y=star;int count=1;Vector curv(1,0);Point curp=arr[0].p;while(count<=n){double minjiao=INF;double mindis=INF;int purpose=-1;for(int i=1;i<=n;i++)if(!arr[i].pos){double jiao=Angle(curv,arr[i].p-curp);double dis=Length(arr[i].p-curp);if(jiao<minjiao||(doublecmp(jiao-minjiao)==0&&dis<mindis)){mindis=dis;minjiao=jiao;purpose=i;}}curv=arr[purpose].p-curp;curp=arr[purpose].p;arr[purpose].pos=count++;}for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)if(arr[j].pos==i)printf(" %d",j);printf("\n");}return 0;}
- POJ 1696 Space Ant
- POJ 1696 Space Ant
- poj 1696 Space Ant
- POJ 1696 Space Ant
- poj 1696 Space Ant
- poj 1696Space Ant
- Poj-1696-Space Ant
- POJ 1696Space Ant
- POJ 1696 Space Ant
- POJ 1696 Space Ant 贪心
- Space Ant - POJ 1696 叉积
- zoj 1429 || poj 1696 Space Ant
- poj 1696 Space Ant--有关极角
- POJ 1696 Space Ant (点积)
- Poj 1696 Space Ant (凸包卷包裹)
- poj 1696 Space Ant(计算几何)
- poj-1696-Space Ant-极角排序
- POJ 1696 Space Ant(卷包裹)
- 安卓修改默认activity
- 多校第四场 区间dp tarjan算法 Polya定理 树状数组
- 2013 多校联合4 1007 Group(hdu 4638)
- hdu 4642 (博弈)
- 字符编码笔记:ASCII、Unicode、UTF-8、UTF-16、UCS、BOM、Endian
- POJ 1696 Space Ant
- 2020 加密2
- Windows store app[Part 4]:深入WinRT的异步机制
- epoll ET LT模式详细
- apt-get install wine1.4 安装出错,解决方法
- Android开发之ProcessState和IPCThreadState类分析
- poj 2391 Ombrophobic Bovines(二分+最大流)
- 龙芯开发(1)——PMON的编译和使用
- Spring--quartz中cronExpression配置说明