POJ 1696 Space Ant 计算几何 叉积的应用
来源:互联网 发布:ubuntu 创建文件夹 编辑:程序博客网 时间:2024/06/05 17:59
题目大意:平面内有一些点,我们要通过一些方式来走遍这所有的点,要求一个点只能走一次,只能向左转而不能向右转。求遍历这些点的顺序。
思路:数据范围是可以怎么搞都0ms的(n<=50,case<=100),所以只要有思路就可以了。
只能左转,想想好像有点像凸包啊。但是这个题要遍历所有的点,所以就把已经走过的点删掉,然后像凸包一样的往前走,每次找一个没走过的极角最小的点走,然后把它标记上。最后都走完就全部遍历完了。
CODE:
#include <cmath>#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define MAX 110#define INF 0x7f7f7f7fusing namespace std;struct Point{int _id;double x,y;double alpha;Point(double _x,double _y):x(_x),y(_y) {}Point() {}Point operator -(const Point &a) {return Point(x - a.x,y - a.y);}bool operator <(const Point &a)const {return alpha < a.alpha;}void Read() {scanf("%d%lf%lf",&_id,&x,&y);}bool Cross(Point &a,Point &b) {Point p1 = *this - a,p2 = *this - b;return p1.x * p2.y - p2.x * p1.y < 0;}}point[MAX],now;int cases,points;int rubbish;inline void Initialize();int main(){for(cin >> cases;cases; --cases) {scanf("%d",&points);Initialize();for(int x,y,i = 1;i <= points; ++i) { point[i].Read();if(point[i].y < now.y)now = point[i];}printf("%d",points);now.x = 0;point[0] = now;for(int i = 1;i <= points; ++i) {for(int j = i + 1;j <= points; ++j)if(point[j].Judge(point[i],point[i - 1]))swap(point[i],point[j]);printf(" %d",point[i]._id);}puts("");}return 0;}inline void Initialize(){now = Point(0,INF);}
0 0
- POJ 1696 Space Ant 计算几何 叉积的应用
- poj 1696 Space Ant(计算几何)
- poj 1696 Space Ant 计算几何
- POJ 1696 Space Ant <计算几何>
- zoj 1429 || poj 1696 Space Ant 计算几何叉积或凸包改进版
- POJ 1696 Space Ant(卷包裹 计算几何)
- POJ 1696 Space Ant (计算几何 + 极角排序)
- poj 1696 Space Ant(叉积的应用)
- POJ 1696 Space Ant(点积的应用)
- poj1696 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
- poj 1696 Space Ant
- POJ 1696 Space Ant
- 循环-28. 求给定序列前N项和之六(15)
- 只读字段的使用
- GeoGeo安装说明
- Hisun——第一次投产总结。
- GeoGeo是什么
- POJ 1696 Space Ant 计算几何 叉积的应用
- 怎样调试GeoGeo脚本
- 玩转Bash脚本:特殊变量
- HDU-4419-Colourful Rectangle(线段树)
- 开-闭原则(OCP)
- css清楚浮动的方法 -常用的3种
- java学习中的疑难杂症(六)---多线程
- Hadoop 单表关联 多表关联
- poj 1143 number game