极角排序

每次选择一个最外围的没选过的点,选择的时候需要利用极角排序进行选择

#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<list>
#include<algorithm>
using namespace std; const double eps=1e-;
struct point
{
int x,y;
double alpha;
int len2;
int id;
} p[];
int T,n;
vector<point>v;
vector<int>ans;
bool flag[]; bool cmp(const point &a, const point &b)
{
if(fabs(a.alpha-b.alpha)<eps) return a.len2<b.len2;
return a.alpha<b.alpha;
} int len2(point a,point b)
{
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
} double f(point a,point b,point c) //返回点a所对应的角的弧度
{
double B2=(double)len2(a,c);
double C2=(double)len2(a,b);
double A2=(double)len2(b,c);
double COSA=(B2+C2-A2)/(*sqrt(B2)*sqrt(C2));
return 3.1415926-acos(COSA);
} int main()
{
scanf("%d",&T);
int Miny=;
while(T--)
{
scanf("%d",&n);
for(int i=; i<=n; i++)
{
scanf("%d%d%d",&p[i].id,&p[i].x,&p[i].y);
Miny=min(Miny,p[i].y);
} memset(flag,,sizeof flag);
ans.clear(); point pre;pre.x=-;pre.y=Miny;
point now;now.x=;now.y=Miny; for(int i=; i<=n; i++)
{
v.clear();
for(int k=; k<=n; k++)
{
if(!flag[p[k].id])
{
p[k].alpha=f(now,p[k],pre);
p[k].len2=len2(p[k],now);
v.push_back(p[k]);
}
}
sort(v.begin(),v.end(),cmp);
flag[v[].id]=;
ans.push_back(v[].id);
pre.x=now.x;
pre.y=now.y;
now.x=v[].x;
now.y=v[].y;
}
printf("%d ",ans.size());
for(int i=; i<ans.size(); i++)
{
printf("%d",ans[i]);
if(i<ans.size()-) printf(" ");
else printf("\n");
}
}
return ;
}

POJ 1696 Space Ant的更多相关文章

  1. poj 1696 Space Ant (极角排序)

    链接:http://poj.org/problem?id=1696 Space Ant Time Limit: 1000MS   Memory Limit: 10000K Total Submissi ...

  2. POJ 1696 Space Ant(极角排序)

    Space Ant Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2489   Accepted: 1567 Descrip ...

  3. poj 1696 Space Ant(模拟+叉积)

    Space Ant Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3840   Accepted: 2397 Descrip ...

  4. POJ 1696 Space Ant 卷包裹法

    Space Ant Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3316   Accepted: 2118 Descrip ...

  5. POJ 1696 Space Ant(点积的应用)

    Space Ant 大意:有一仅仅蚂蚁,每次都仅仅向当前方向的左边走,问蚂蚁走遍全部的点的顺序输出.開始的点是纵坐标最小的那个点,開始的方向是開始点的x轴正方向. 思路:从開始点開始,每次找剩下的点中 ...

  6. 2018.07.04 POJ 1696 Space Ant(凸包卷包裹)

    Space Ant Time Limit: 1000MS Memory Limit: 10000K Description The most exciting space discovery occu ...

  7. poj 1696:Space Ant(计算几何,凸包变种,极角排序)

    Space Ant Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2876   Accepted: 1839 Descrip ...

  8. POJ 1696 - Space Ant 凸包的变形

    Technorati Tags: POJ,计算几何,凸包 初学计算几何,引入polygon后的第一个挑战--凸包 此题可用凸包算法做,只要把压入凸包的点从原集合中排除即可,最终形成图形为螺旋线. 关于 ...

  9. POJ 1696 Space Ant(凸包变形)

    Description The most exciting space discovery occurred at the end of the 20th century. In 1999, scie ...

  10. POJ 1696 Space Ant --枚举,模拟,贪心,几何

    题意: 有很多点,从最右下角的点开始走起,初始方向水平向右,然后以后每步只能向左边走,问最多能走多少个点. 解法: 贪心的搞的话,肯定每次选左边的与它夹角最小的点,然后走过去. 然后就是相当于模拟地去 ...

随机推荐

  1. iOS NSString类中获取子字符串

    NSString类中提供了这样三个方法用于获取子字符串: – substringFromIndex://取字符串长度从0开始,当index=str.length时字符串为空"" – ...

  2. keepalived: Compile & startup

    first get keepalived source from git: git clone https://github.com/acassen/keepalived then unzip and ...

  3. stray '/241' in program 错误

    意思是c/c++中的编译错误. 该错误是指源程序中有非法字符,需要去掉非法字符.一般是由于从别的地方粘贴过来造成的. 方法:1.把所粘的文字放到记事本里就行了 2.把出错行的空格删掉重新打一下试试.

  4. ARP/代理ARP

    1.ARP首先讲到ARP,ARP是地址解析协议,它的作用是在以太网环境下,通过3层的IP地址来找寻2层的MAC地址,得到一张ARP缓存表.转发数据的时候根据ARP缓存表来进行传输.下图详细说明数据传输 ...

  5. Sea.Js使用入门

    1.Sea.Js是什么 seajs相对于RequireJs与LabJS就比较年轻,2010年玉伯发起了这个开源项目,SeaJS遵循CMD规范,与RequireJS类似,同样做为模块加载器.示例 // ...

  6. MySQL 5.7 for Windows 解压缩版配置安装

    从MYSQL5.7.6开始,安装MYSQL提示“请键入 NET HELPMSG 3534 以获得更多的帮助”的解决办法 今天安装MySQL提示如下错误: ----------------------- ...

  7. 改MAC地址

    Google TMAC v6. Or click here

  8. WebSphere MQ 入门指南【转】

    WebSphere MQ 入门指南 转自 WebSphere MQ 入门指南 - 大CC - 博客园http://www.cnblogs.com/me115/p/3456407.html 这是一篇入门 ...

  9. Android Studio没有导包快捷键怎么办

    Android Studio没有导包快捷键,那怎么办呢? 在使用Eclipse开发Android应用时,开发者往往会使用Shift+Ctrl+O快捷键来快速导入所有的包,和移除未使用的包.但这个快捷键 ...

  10. centos搭建nginx环境

    1.yum install  pcre* 2.wget http://nginx.org/download/nginx-1.7.8.tar.gz 3.tar -zxvf nginx-1.7.8.tar ...