poj 1696 极角排序求最长逆时针螺旋线
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 4970 | Accepted: 3100 |
Description
- It can not turn right due to its special body structure.
- It leaves a red path while walking.
- It hates to pass over a previously red colored path, and never does that.
The pictures transmitted by the Discovery space ship depicts that plants in the Y1999 grow in special points on the planet. Analysis of several thousands of the pictures have resulted in discovering a magic coordinate system governing the grow points of the plants. In this coordinate system with x and y axes, no two plants share the same x or y.
An M11 needs to eat exactly one plant in each day to stay alive. When it eats one plant, it remains there for the rest of the day with no move. Next day, it looks for another plant to go there and eat it. If it can not reach any other plant it dies by the end of the day. Notice that it can reach a plant in any distance.
The problem is to find a path for an M11 to let it live longest.
Input is a set of (x, y) coordinates of plants. Suppose A with the coordinates (xA, yA) is the plant with the least y-coordinate. M11 starts from point (0,yA) heading towards plant A. Notice that the solution path should not cross itself and all of the turns should be counter-clockwise. Also note that the solution may visit more than two plants located on a same straight line. 
Input
Output
Sample Input
2
10
1 4 5
2 9 8
3 5 9
4 1 7
5 3 2
6 6 3
7 10 10
8 8 1
9 2 4
10 7 6
14
1 6 11
2 11 9
3 8 7
4 12 8
5 9 20
6 3 2
7 1 6
8 2 13
9 15 1
10 14 17
11 13 19
12 5 18
13 7 3
14 10 16
Sample Output
10 8 7 3 4 9 5 6 2 1 10
14 9 10 11 5 12 8 7 6 13 4 14 1 3 2 这题好像可以直接用极角排序去写 直接套模板去写
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <queue>
#include <map>
#include <vector>
#include <set>
#include <string>
#include <math.h> using namespace std; struct point {
double x, y;
int idx;
point() {}
point(int x, int y) : x(x), y(y) {}
point operator - (const point & a) const {
return point(x - a.x, y - a.y);
}
double operator ^ (const point & b) const {
return x * b.y - y * b.x;
}
double operator * (const point & a) const {
return x * a.x + y * a.y;
}
} p[];
double dist(point a, point b) {
return sqrt((a - b) * (a - b));
}
int pos;
int cmp(point a, point b) {
double temp = (a - p[pos]) ^ (b - p[pos]);
if (temp == ) return dist(p[pos], a) < dist(p[pos], b);
else if(temp < ) return ;
else return ;
}
int main() {
int t, n;
scanf("%d", &t);
while(t-- ) {
scanf("%d", &n);
double x, y;
for (int i = ; i < n ; i++) {
scanf("%d%lf%lf", &p[i].idx, &p[i].x, &p[i].y);
if (p[i].y < p[].y || p[i].y == p[].y && p[i].x < p[].x) swap(p[i], p[]);
}
pos = ;
for (int i = ; i < n ; i++) {
sort(p + i, p + n, cmp);
pos++;
}
printf("%d", n);
for (int i = ; i < n ; i++)
printf(" %d", p[i].idx);
printf("\n");
}
return ;
}
poj 1696 极角排序求最长逆时针螺旋线的更多相关文章
- poj 1696 极角排序(解题报告)
#include<iostream> #include<cmath> #include<algorithm> using namespace std; double ...
- poj 1696(极角排序)
Space Ant Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 3924 Accepted: 2457 Descrip ...
- POJ 3080 Blue Jeans (求最长公共字符串)
POJ 3080 Blue Jeans (求最长公共字符串) Description The Genographic Project is a research partnership between ...
- L3-021 神坛(极角排序求三角形最小面积)
在古老的迈瑞城,巍然屹立着 n 块神石.长老们商议,选取 3 块神石围成一个神坛.因为神坛的能量强度与它的面积成反比,因此神坛的面积越小越好.特殊地,如果有两块神石坐标相同,或者三块神石共线,神坛的面 ...
- POJ - 2007 极角排序(Java 实现)
POJ 2007 将所有的点按逆时针输出 import java.io.*; import java.util.*; public class Main { static class Point im ...
- Scrambled Polygon POJ - 2007 极角排序
题意: 给你n个点,这n个点可以构成一个多边形(但是不是按顺序给你的).原点(0,0)为起点,让你按顺序逆序输出所有点 题解: 就是凸包问题的极角排序 用double一直Wa,改了int就可以了 // ...
- hdu5785(极角排序求所有锐角钝角个数)
做法很显然,求出所有的锐角和钝角就能求出有多少个锐角三角形了. 我用了愚钝的方法,写了两三个小时... 看了下别人简单的代码.学习了下做法. sort(temp+,temp+cnt+);//排序 Fo ...
- Wall--POJ1113(极角排序+求凸包)
http://poj.org/problem?id=1113 题目大意:现在要给n个点,让你修一个围墙把这些点围起来,距离最小是l 分析 :现在就是求凸包的周长然后再加上一个圆的周长 #includ ...
- poj 1743 后缀数组 求最长不重叠重复子串
题意:有N(1 <= N <=20000)个音符的序列来表示一首乐曲,每个音符都是1..88范围内的整数,现在要找一个重复的主题. “主题”是整个音符序列的一个子串,它需要满足如下条件:1 ...
随机推荐
- hbase thrift 访问队列
public class CallQueue implements BlockingQueue<Runnable> { private static Log LOG = LogFact ...
- canvas的常见用法
Canvas canvas是一种抽象概念,是2D图形系统中的重要部分,canvas一系列函数最终都是android 2D图形库Skia的一些列封装,对应在SKCanvas.cpp.canvas在系统中 ...
- JVM学习--(五)垃圾回收器
上一篇我们介绍了常见的垃圾回收算法,不同的算法各有各的优缺点,在JVM中并不是单纯的使用某一种算法进行垃圾回收,而是将不同的垃圾回收算法包装在不同的垃圾回收器当中,用户可以根据自身的需求,使用不同的垃 ...
- 《深入理解JAVA虚拟机》笔记1
java程序运行时的内存空间,按照虚拟机规范有下面几项: )程序计数器 指示下条命令执行地址.当然是线程私有,不然线程怎么能并行的起来. 不重要,占内存很小,忽略不计. )方法区 这个名字很让我迷惑. ...
- Java框架数据库连接池比较 [转贴 2010-3-20 9:57:51]
现在常用的开源数据连接池主要有c3p0,dbcp和proxool三种,其中: ¨hibernate开发组推荐使用c3p0; ¨spring开发组推荐使用dbcp (dbcp连接池有weblogic连接 ...
- Apache Flink Quickstart
Apache Flink 是新一代的基于 Kappa 架构的流处理框架,近期底层部署结构基于 FLIP-6 做了大规模的调整,我们来看一下在新的版本(1.6-SNAPSHOT)下怎样从源码快速编译执行 ...
- Docker 生态概览
Docker 和容器技术的发展可谓是日新月异,本文试图以全局的视角来梳理一下 docker 目前的生态圈.既然是概览,所以不会涉及具体的技术细节. Docker 自从发布以来发生了很多的变化,并且有些 ...
- Spring请求参数校验
SpringMVC支持的数据校验是JSR303的标准,通过在bean的属性上打上@NotNull.@Max等进行验证.JSR303提供有很多annotation接口,而SpringMVC对于这些验证是 ...
- spring的简单入门
spring是一个轻量级的JavaEE解决方案,是众多优秀设计模式的整合.spring的核心是:(工厂)容器 1.设计模式:解决一些特定问题的经典代码.共有23中设计模式(工厂,单例,代理,适配,装饰 ...
- 面向对象的WebAPI框架XXL-HEX
<面向对象的WebAPI框架XXL-HEX> 一.简介 1.1 概述 XXL-HEX 是一个简单易用的WebAPI框架, 拥有 "面向对象.数据加密.跨语言" 的 ...