POJ 1696Space Ant Graham-scan
来源:互联网 发布:java有指针吗 编辑:程序博客网 时间:2024/05/17 22:45
给你 n个点求一个逆时针的螺旋轨迹
先找到最下方的点然后利用Graham-scan每次求得下一个点
ACcode:
#include <iostream>#include <cstdio>#include <cmath>#include <algorithm>using namespace std;int sgn(double x){ if(fabs(x)<1e-8)return 0; if(x<0)return -1; return 1;}struct Point{ double x,y; int id; Point(){} Point(double _x,double _y){ x=_x; y=_y; } Point(double _x,double _y,int _id){ x=_x; y=_y; id=_id; } Point operator-(const Point &b)const{ return Point(x-b.x,y-b.y); } double operator*(const Point &b)const{ return x*b.x+y*b.y; } double operator^(const Point &b)const{ return x*b.y-y*b.x; } double dist(Point p){ return hypot(x-p.x,y-p.y); } bool operator <(Point b)const{ return sgn(y-b.y)==0?sgn(x-b.x)<0:y<b.y; }}my[66];int id=1;bool cmp(Point a,Point b){ if(sgn((a-my[id])^(b-my[id]))==0)return a.dist(my[id])<b.dist(my[id]); else if(sgn((a-my[id])^(b-my[id]))<0)return 0; return 1;}void doit(int n){ id=1; for(int i=2;i<=n;++i,++id) sort(my+i,my+1+n,cmp);}int main(){ int loop; scanf("%d",&loop); while(loop--){ int n; scanf("%d",&n); for(int i=1;i<=n;++i){ int id; double x,y; scanf("%d%lf%lf",&id,&x,&y); my[i]=Point(x,y,id); } sort(my+1,my+1+n); doit(n); printf("%d",n); for(int i=1;i<=n;++i) printf(" %d",my[i].id); putchar('\n'); } return 0;}
0 0
- POJ 1696Space Ant Graham-scan
- 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 2007 Graham-Scan算法
- 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(计算几何)
- <thinking in java 4>学习笔记
- thread pool
- 关于程序员选择就业单位的一点思考
- ADTS格式AAC
- Renesas+LTC6804-1的SPI通信
- POJ 1696Space Ant Graham-scan
- HDU 1013 Digital Roots(两种方法,求数字根)
- Mysql开发规范
- 利用INF文件来修改注册表
- 安卓开发代码规范以及命名规范
- View的14个方法
- map 按value排序
- 详解C++各种智能指针: auto_ptr, shared_ptr, weak_ptr, scoped_ptr
- 安装pptpd