Space Ant--poj1696(极角排序)
http://poj.org/problem?id=1696
极角排序是就是字面上的意思 按照极角排序
题目大意:平面上有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=,double y=):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 ;
if(fabs(t)<ESP)
return ;
return -;
}
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[N]; double dist(Point a1,Point a2)
{
return sqrt((a1-a2)*(a1-a2));
}
int pos=; int cmp(Point a1,Point a2)
{
int t=(a1-p[pos])^(a2-p[pos]);
if(t==)
return dist(p[pos],a1) < dist(p[pos],a2);
else if(t<) return false;
else
return true;
} int main()
{
int T,n;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(int i=;i<n;i++)
{
scanf("%d %lf %lf",&p[i].index,&p[i].x,&p[i].y);
if(p[i].y<p[].y || (p[i].y==p[].y && p[i].x<p[].x))
swap(p[i],p[]);
}
pos=; for(int i=;i<n;i++)
{
sort(p+i,p+n,cmp);
pos++;
}
printf("%d",n);
for(int i=;i<n;i++)
printf(" %d",p[i].index);
printf("\n");
}
return ;
}
Space Ant--poj1696(极角排序)的更多相关文章
- poj 1696 Space Ant (极角排序)
链接:http://poj.org/problem?id=1696 Space Ant Time Limit: 1000MS Memory Limit: 10000K Total Submissi ...
- POJ 1696 Space Ant(极角排序)
Space Ant Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 2489 Accepted: 1567 Descrip ...
- Space Ant(极角排序)
Space Ant http://poj.org/problem?id=1696 Time Limit: 1000MS Memory Limit: 10000K Total Submissions ...
- POJ 1696 Space Ant 【极角排序】
题意:平面上有n个点,一只蚂蚁从最左下角的点出发,只能往逆时针方向走,走过的路线不能交叉,问最多能经过多少个点. 思路:每次都尽量往最外边走,每选取一个点后对剩余的点进行极角排序.(n个点必定能走完, ...
- Space Ant---poj1696(极角排序)
题目链接:http://poj.org/problem?id=1696 题意:给你n个点,然后我们用一条线把它们连起来,形成螺旋状: 首先找到左下方的一个点作为起点,然后以它为原点进行极角排序,找到极 ...
- poj 1696:Space Ant(计算几何,凸包变种,极角排序)
Space Ant Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 2876 Accepted: 1839 Descrip ...
- poj1696 Space Ant【计算几何】
含极角序排序模板. Space Ant Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5334 Accepted: ...
- 二维坐标系极角排序的应用(POJ1696)
Space Ant Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 3170 Accepted: 2029 Descrip ...
- POJ-1696 Space Ant 凸包版花式水过!
Space Ant 明天早上最后一科毛概了,竟然毫无复习之意,沉迷刷题无法自拔~~ 题意:说实 ...
- poj1696 Space Ant
地址: 题目: Space Ant Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4295 Accepted: 2697 ...
随机推荐
- 【HEVC简介】SAO-Sample Adaptive Offset, 样本自适应偏移量
paper: Sample Adaptive Offset for HEVC <HEVC标准介绍.HEVC帧间预测论文笔记>系列博客,目录见:http://www.cnblogs.com/ ...
- Charles Petzold 编程界大师,世界顶级技术作家 《CODE》值得阅读
<CODE>The Hidden Language of Computer Hardware and Software 从书内容的第一页开始就惊叹于作者的耐心和责任心 整本书以两个隔街对窗 ...
- iOS开发内购全套图文教程
2015年最全的内购图文教程,首先是填各种资料,最后是代码,废话不多说,直接上图 ======================第一部分协议=============== 第一步 第二步 第三步 第四步 ...
- 递归的可视化(Fibonacci)
递归的可视化 修改递归函数,使其能够显示打印出每次函数递归调用的形参的值. 每一级调用的输出都带有一级缩进,就是使得程序的输出清晰.有趣并且有含义. 思路 以斐波那契数列为例,假设n=5,递归的形参如 ...
- iOS代理模式
iOS代理模式的简单理解:当一个对象无法直接获取到另一个对象的指针,又希望对那个变量进行一些操作时,可以使用代理模式. 代理主要由三部分组成: (1)协议:用来指定代理双方可以做什么,必须做什么. ( ...
- No-7.系统信息相关命令
系统信息相关命令 本节内容主要是为了方便通过远程终端维护服务器时,查看服务器上当前 系统日期和时间 / 磁盘空间占用情况 / 程序执行情况 本小结学习的终端命令基本都是查询命令,通过这些命令对系统资源 ...
- mysql中ibatis的limit动态传参
param.put("pageNo",pageNo); param.put("pageSize",pageSize); sqlMap中的用法 limit $ ...
- 分享点干货(此this非彼this)this的详细解读
在javascript编程中,this关键字经常让初学者感到迷惑,这里,针对此this根据查阅的资料和个人的理解分享一下,纯手打,大神勿喷. 首先先说一下this的指向,大致可以分为以下四种. 1.作 ...
- 35个Redis面试题
1.什么是redis? Redis 是一个基于内存的高性能key-value数据库. 2.Reids的特点 Redis本质上是一个Key-Value类型的内存数据库,很像memcached,整个数据库 ...
- python 04 学生信息管理系统
今天任务不多,做了学生信息管理系统1.0,使用字典存储学生个体信息,列表存储学生字典.注意dict定义要在循环体内,若定义成全局变量或循环体外,则旧数据会被新数据覆盖.dict属于可变类型数据,内容改 ...