POJ 1696 Space Ant 极角排序(叉积的应用)

时间:2022-08-24 12:51:48

题目大意:给出n个点的编号和坐标,按逆时针方向连接着n个点,按连接的先后顺序输出每个点的编号。

题目思路:Cross(a,b)表示a,b的叉积,若小于0:a在b的逆时针方向,若大于0a在b的顺时针方向。每次都sort一下,找出在当前点逆时针方向的最远的点。数据很小O(N*N*log(N))的复杂度0s AC了……

#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#define INF 0x3f3f3f3f
#define MAX 100005 using namespace std; int n,pos,ans[MAX]; struct node
{
int id,x,y;
}point[MAX]; int Dist(int x1,int y1,int x2,int y2)
{
return sqrt((x1-x2)*(x1-x2)*1.0 + (y1-y2)*(y1-y2)*1.0);
} int Cross(int x1,int y1,int x2,int y2,int x3,int y3)
{
return (x1-x2)*(y1-y3)-(x1-x3)*(y1-y2);
} bool cmp(struct node A,struct node B)
{
int op=Cross(point[pos].x,point[pos].y,A.x,A.y,B.x,B.y);
if(op>)
return true;
else if(op== && Dist(point[pos].x,point[pos].y,A.x,A.y)<Dist(point[pos].x,point[pos].y,B.x,B.y))
return true;
return false;
} int main()
{
int T,cnt;
scanf("%d",&T);
while(T--)
{
pos=;
cnt=;
memset(ans,,sizeof(ans));
scanf("%d",&n);
scanf("%d%d%d",&point[].id,&point[].x,&point[].y);
for(int i=;i<n;i++)
{
scanf("%d%d%d",&point[i].id,&point[i].x,&point[i].y);
if(point[i].y < point[].y)//找出起点:左下方的点
swap(point[],point[i]);
else if(point[i].y==point[].y && point[i].x < point[].x)
swap(point[],point[i]);
}
sort(point,point+n,cmp);
ans[cnt++]=point[pos++].id;
for(int i=;i<n;i++)
{
sort(point+i,point+n,cmp);
ans[cnt++]=point[pos++].id;
}
printf("%d ",cnt);
for(int i=;i<cnt;i++)
printf("%d%c",ans[i],i==cnt-?'\n':' ');
}
return ;
}

POJ 1696 Space Ant 极角排序(叉积的应用)的更多相关文章

  1. poj 1696 Space Ant 极角排序

    #include<cstdio> #include<cstring> #include<cmath> #include<iostream> #inclu ...

  2. poj 1696 Space Ant(模拟&plus;叉积)

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

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

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

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

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

  5. poj 1696&colon;Space Ant(计算几何,凸包变种,极角排序)

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

  6. POJ 1696 Space Ant 【极角排序】

    题意:平面上有n个点,一只蚂蚁从最左下角的点出发,只能往逆时针方向走,走过的路线不能交叉,问最多能经过多少个点. 思路:每次都尽量往最外边走,每选取一个点后对剩余的点进行极角排序.(n个点必定能走完, ...

  7. 2018&period;07&period;04 POJ 1696 Space Ant(凸包卷包裹)

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

  8. POJ 1696 Space Ant 卷包裹法

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

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

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

随机推荐

  1. Android 下载文件及写入SD卡

    Android 下载文件及写入SD卡,实例代码 <?xml version="1.0" encoding="utf-8"?> <LinearL ...

  2. 【转】C&num; 解析JSON方法总结

    http://blog.csdn.net/jjhua/article/details/51438317 主要参考http://blog.csdn.NET/joyhen/article/details/ ...

  3. 解决vue路径中&num;号

    在router文件夹下的js文件中,更改配置增加 mode: 'history'; vue-router官方文档:https://router.vuejs.org/zh-cn/essentials/h ...

  4. &lbrack;USACO08JAN&rsqb;haybale猜测Haybale Guessing

    题目描述 The cows, who always have an inferiority complex about their intelligence, have a new guessing ...

  5. Springboot 拦截器 依赖注入失败

    解决方案2种. ====1 https://blog.csdn.net/shunhua19881987/article/details/78084679 ====2 https://www.cnblo ...

  6. I&sol;O 模型与 Java

    本文主要记录 Java 中 I/O 模型及相关知识点 .另,由于自身知识水平有限,如有不正之处,望各位能够谅解,欢迎批评指正! 一.I/O 基础 由于 Java 中 I/O 相关的 API ,无论是 ...

  7. iPhone照片格式heic图片怎么打开

    苹果自iOS11系统之后默认的是heic图片格式,在电脑和安卓中都无法直接查看,需要将其转换图片格式,那苹果heic图片怎么转换成jpg格式?下面我们一起来看看吧! 使用工具:电脑.图片 操作方法: ...

  8. Linux内核之进程地址空间

    Linux内核之进程地址空间 内核中的函数以相当直接了当的方式获得动态内存: __get_free_pages 或 alloc_pages从分区页框分配器中获得页框; kmem_cache_alloc ...

  9. Codeforces&period;662C&period;Binary Table&lpar;状压 FWT&rpar;

    题目链接 \(Description\) 给定一个\(n\times m\)的\(01\)矩阵,你可以选择一些行和一些列并将其中所有的\(01\)反转.求操作后最少剩下多少个\(1\). \(n\le ...

  10. Netty:option和childOption参数设置说明

    Channel配置参数 (1).通用参数 CONNECT_TIMEOUT_MILLIS :   Netty参数,连接超时毫秒数,默认值30000毫秒即30秒. MAX_MESSAGES_PER_REA ...