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 ...
随机推荐
- ural 2066. Simple Expression
2066. Simple Expression Time limit: 1.0 secondMemory limit: 64 MB You probably know that Alex is a v ...
- 【LINUX/UNIX网络编程】之简单多线程服务器(多人群聊系统)
RT,Linux下使用c实现的多线程服务器.这个真是简单的不能再简单的了,有写的不好的地方,还希望大神轻拍.(>﹏<) 本学期Linux.unix网络编程的第四个作业. 先上实验要求: [ ...
- python 代码片段18
#coding=utf-8 f=open('text.txt','w') f.write('foo\n') f.write('bar\n') f.close() f=open('test.txt',' ...
- Java 集合系列18之 Iterator和Enumeration比较
概要 这一章,我们对Iterator和Enumeration进行比较学习.内容包括:第1部分 Iterator和Enumeration区别第2部分 Iterator和Enumeration实例 转载请 ...
- IOS关于UIViewController之间的切换
IOS关于UIViewController之间的切换 1.NavigationController切换UIViewController的两种方式 方法一右侧进入 1 SecondViewControl ...
- [杂谈] There is a Doctor in My Computer.
(p.s. 附带手写翻译,有错轻喷) Admin: Hi. (嗨) Doctor: How do you do? What brings you to see me? ...
- 转:关于垂直网格与CSS基线对其的探讨
网页设计布局中一直比较流行网格对齐,但只是针对水平的对齐,很少或者没有涉及垂直对齐,这篇文章很详细的讲解了垂直网格,乃至基线对其的相关,而css3中的多列布局的也使其显得更为重要,因此还是很有必要去了 ...
- Java_解密ThreadLocal
概述 相信读者在网上也看了很多关于ThreadLocal的资料,很多博客都这样说:ThreadLocal为解决多线程程序的并发问题提供了一种新的思路:ThreadLocal的目的是为了解决多线程访问资 ...
- Linux 的cp命令
Linux 的cp命令 功能: 复制文件或目录说明: cp指令用于复制文件或目录,如同时指定两个以上的文件或目录,且最后的目的地是一个已经存在的目录,则它会把前面指定的所有文件或目录复制到此目录中.若 ...
- node.js不得不说的12点内容
1.node.js,服务器端的javascript,它允许在后端(脱离浏览器环境)运行javascript代码. 2.事件驱动.异步式I/O的编程模式(单线程)是其核心. 3.node.js的java ...