Space Ant---poj1696(极角排序)
题目链接:http://poj.org/problem?id=1696
题意:给你n个点,然后我们用一条线把它们连起来,形成螺旋状;
首先找到左下方的一个点作为起点,然后以它为原点进行极角排序,找到极角最小的那个点,如果又多个选距离近的,每次都这样循环找n个点即可;
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h> using namespace std; typedef long long LL; const double eps = 1e-;
const int N = ; struct point
{
int x, y, Id; point(){}
point(int x, int y) : x(x), y(y) {} point operator - (const point &b)const
{
return point(x-b.x, y-b.y);
}
int operator ^ (const point &b)const
{
return x*b.y - b.x*y;
}
}; int dist(point a, point b)
{
return (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y);
} int start, n; point p[N]; bool cmp(point a, point b)
{
int k = (a-p[start])^(b-p[start]);
if(k == )
return dist(p[start], a)<dist(p[start], b);
return k>;
} int main()
{
int T; scanf("%d", &T); while(T--)
{
scanf("%d", &n); for(int i=; i<n; i++)
{
scanf("%d %d %d", &p[i].Id, &p[i].x, &p[i].y);
if(p[i].y < p[].y || (p[i].y==p[].y && p[].x>p[i].x))
swap(p[i], p[]);
} start = ; for(int i=; i<n; i++)
{
sort(p+i, p+n, cmp); start ++;
} printf("%d", n); for(int i=; i<n; i++)
printf(" %d", p[i].Id); 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个点必定能走完, ...
- 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 ...
随机推荐
- So you want to be a 2n-aire?[HDU1145]
So you want to be a 2n-aire?Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java ...
- HDU 3090 (贪心)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3090 题目大意:一共n段路.每段路每千米都会被抢劫一定数量,可以雇佣武士护卫m千米.问最少被抢劫数量 ...
- nginx配置文件中的location中文详解
location 语法:location [=|~|~*|^~] /uri/ { … }默认:否 上下文:server 这个指令随URL不同而接受不同的结构.你可以配置使用常规字符串和正则表达式.如果 ...
- 51Nod 1136 欧拉函数 Label:数论
对正整数n,欧拉函数是少于或等于n的数中与n互质的数的数目.此函数以其首名研究者欧拉命名,它又称为Euler's totient function.φ函数.欧拉商数等.例如:φ(8) = 4(Phi( ...
- Springmvc+Hibernate在Eclipse启动Tomcat需要很长时间的解决方法
最近在学习SpringMvc开发,有一个提问困扰了很久,就是在Eclipse启动Tomcat需要很长时间,大概要1分多钟. 启动日志: 九月 08, 2016 8:59:01 下午 org.apach ...
- X-UA-Compatible/IE=EmulateIE7/IE=7
1.<meta http-equiv="X-UA-Compatible" content="IE=5" /> 像是使用了 Windows Inter ...
- Update UI from an asynchronous thread
One of the most common tasks you need to perform in a Windows Phone application is updating the UI f ...
- LruCache
参考文章: LruCache源码解析
- Maya 建模完成后的整理
我们在使用Maya建模完成后可能会进行发布,为了自己或他人的方便使用,我们需要对建立好的模型进行些处理: 1. 删除历史记录:选择模型,Edit -> Delete by Type -> ...
- Introduction of Team Member
1. 姓名:xx 性别:男 出生日期:1993.04.16 班级:110616班 职务:小班长 爱好:唱歌.排球 2. 姓名:xxx 性别:男 出生日期:1993.4.20 3. 姓名:xxx 性别: ...