poj1696 Space Ant
来源:互联网 发布:成都管家婆软件代理 编辑:程序博客网 时间:2024/06/06 17:28
题目链接:http://poj.org/problem?id=1696
题意:给你n个点的坐标,并给出每个点的序号,让你找一条,不向右拐的最长的路径
解析:每次都找到一个基准点做极角排序,下一次则选则相对于之前那一个点最小极角的点,再接着进行极角排序,这样生成的路径就是所求的
#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>#include <iostream>#include <vector>#include <queue>#include <set>using namespace std;const int maxn = 1000+100;struct point{ int id; double x,y; point() {} point(double _x,double _y) { x = _x; y = _y; } bool operator < (const point &b)const { if(y==b.y) return x<b.x; return y<b.y; }}a[maxn];int cnt = 0;double x_mul(point p0,point p1,point p2){ return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);}double dis(point a,point b){ return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}int cmp(point p1,point p2){ if(x_mul(a[cnt],p1,p2)==0) return dis(a[cnt],p1)<dis(a[cnt],p2); return x_mul(a[cnt],p1,p2)>0;}int main(){ int t; cin>>t; while(t--) { int n; scanf("%d",&n); for(int i=0;i<n;i++) scanf("%d %lf %lf",&a[i].id,&a[i].x,&a[i].y); sort(a,a+n); cnt = 0; for(int i=1;i<n;i++) { sort(a+i,a+n,cmp); cnt++; } printf("%d",n); for(int i=0;i<n;i++) printf(" %d",a[i].id); puts(""); } return 0;}
0 0
- POJ1696-Space Ant
- poj1696 Space Ant
- POJ1696-Space Ant
- Poj1696 Space Ant
- poj1696 Space Ant
- poj1696 Space Ant 计算几何
- poj1696 Space Ant 点积,叉积,夹角
- POJ1696 Space Ant 【凸包-ToLeft-Test】
- POJ1696-Space Ant(凸包)
- poj1696 Space Ant(半平面交)
- POJ1696---Space Ant(基础计算几何:极角排序)
- POJ1696 space ant(计算几何,极角排序)
- poj1696 Space Ant (极角排序,叉积)
- poj1696
- poj1696
- poj1696
- Space Ant
- Space Ant
- HTTP协议详解
- 深度学习(17):无人机
- 基于Java语言的安卓程序编写之七TextView控件
- Hibernate框架学习(一)
- IOCP编程(中)
- poj1696 Space Ant
- C++入门②:Hello World
- 【Android】图形图像处理之"自定义绘画"
- Cache和Buffer的区别
- docker安装-升级-卸载
- Android布局优化
- Linux 文件描述符简介(file descriptor)
- 第七届蓝桥杯解析参考
- 深度学习(18):无人汽车