Space Ant--poj1696(极角排序)
2016-05-10 15:32
92 查看
http://poj.org/problem?id=1696
极角排序是就是字面上的意思 按照极角排序
题目大意:平面上有n个点然后有一只蚂蚁他只能沿着点向左走 求最多能做多少点
分析: 其实还不知道极角排序到底是什么, 但是又好像知道一点 必须一直排序 然后一直找到最左的点就行了
极角排序是就是字面上的意思 按照极角排序
题目大意:平面上有n个点然后有一只蚂蚁他只能沿着点向左走 求最多能做多少点
分析: 其实还不知道极角排序到底是什么, 但是又好像知道一点 必须一直排序 然后一直找到最左的点就行了
#include<stdio.h> #include<math.h> #include<algorithm> #include<iostream> #include<string.h> #include<stdlib.h> #include<ctype.h> #include<vector> using namespace std; #define INF 0xfffffff #define ESP 1e-8 #define memset(a,b) memset(a,b,sizeof(a)) #define N 2100 struct Point { double x,y; int index; Point(double x=0,double y=0):x(x),y(y){} Point operator - (const Point &temp)const{ return Point(x-temp.x,y-temp.y); } Point operator + (const Point &temp)const{ return Point(x+temp.x,y+temp.y); } int operator ^(const Point &temp)const{///求叉积 double t=(x*temp.y)-(y*temp.x); if(t>ESP) return 1; if(fabs(t)<ESP) return 0; return -1; } double operator * (const Point &temp)const{ return x*temp.x+y*temp.y; } bool operator == (const Point &temp)const{ return (x==temp.x)&&(y==temp.y); } }p ; double dist(Point a1,Point a2) { return sqrt((a1-a2)*(a1-a2)); } int pos=0; int cmp(Point a1,Point a2) { int t=(a1-p[pos])^(a2-p[pos]); if(t==0) return dist(p[pos],a1) < dist(p[pos],a2); else if(t<0) return false; else return true; } int main() { int T,n; scanf("%d",&T); while(T--) { scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%d %lf %lf",&p[i].index,&p[i].x,&p[i].y); if(p[i].y<p[0].y || (p[i].y==p[0].y && p[i].x<p[0].x)) swap(p[i],p[0]); } pos=0; for(int i=1;i<n;i++) { sort(p+i,p+n,cmp); pos++; } printf("%d",n); for(int i=0;i<n;i++) printf(" %d",p[i].index); printf("\n"); } return 0; }
相关文章推荐
- 使用vb.net获取相应文件夹下相应文件的个数并显示
- poj1465Multiple(经典BFS+余数判重)
- 存储班长信息的学生类
- TFS环境搭建
- sublime 一些常用功能和快捷键
- [LeetCode]题解(python):147-Insertion Sort List
- webview同步cookies
- 关于JAVA中一些简单加密算法的思考
- 数据结构-二叉树(binary tree)-二叉查找树(binary search tree)
- PHP+MongoDB+Coreseek/Sphinx(xmlpipe2数据源)打造千万级搜索引擎
- Java多线程知识小抄集(三)
- Java多线程知识小抄集(三)
- SSH框架总结(框架分析+环境搭建+实例源码下载)
- 动态url修改建议
- win10 TortoiseSVN 部分图标不显示
- VS查看结构体指针变量的方法
- php连接sql server数据库库
- centOS6.7下部署LAMP
- java.lang.IllegalArgumentException介绍
- linux下创建tuntap网络设备