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 ...
随机推荐
- CodeForces#275--DIV 2--B(BinarySearch)(!!)
B. Friends and Presents time limit per test 1 second memory limit per test 256 megabytes input stand ...
- BZOJ4699 : 树上的最短路
这道题主要是要解决以下两个问题: 问题1: 给定一个点$x$,如何取出所有经过它的下水道? 一条下水道经过$x$等价于它起点在$x$的子树里面且终点不在$x$的子树里面,或者两端点的lca就是$x$. ...
- Java web项目在linux环境下自动编译和部署脚本
自动编译脚本 build.sh, 放置在项目根目录下. #!/bin/bash # check args # init path CURRPATH=`pwd` LIBDIR="$CURRPA ...
- Colorado Potato Beetle(CF的某道) & 鬼畜宽搜
题意: 一个人在一张大图上走,给你路径与起点,求他走出的矩形面积并.(大概这个意思自行百度标题... SOL: 与其说这是一道图论题不如说是一道生动活泼的STL-vector教学.... 离散化宽搜, ...
- JS正则获取参数值
var geturl = function(url){ var ret = {}; var queryStr=url.replace(/^[^\?#]*\??/g,'').replace(/#DIAL ...
- lua 获取文件名和扩展名
local str = "aaa.bbb.bbb.txt" --获取文件名 function getFileName(str) local idx = str:match(&quo ...
- Reids 主从同步
安装Redis(主从两个装在同一服务器上) 参考地址:http://www.cnblogs.com/kgdxpr/p/3550633.html 主安装在“/usr/local/redis-Master ...
- ACM: Find MaxXorSum 解题报告-字典树
Find MaxXorSum Time Limit:2000MS Memory Limit:65535KB 64bit IO Format: Description Given n non-negat ...
- spring源码学习之路---深入AOP(终)
作者:zuoxiaolong8810(左潇龙),转载请注明出处,特别说明:本博文来自博主原博客,为保证新博客中博文的完整性,特复制到此留存,如需转载请注明新博客地址即可. 上一章和各位一起看了一下sp ...
- NetDMA
NetDMA provides operating system support for direct memory access (DMA) offload. TCP/IP uses NetDMA ...