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 ...
随机推荐
- Jmeter(二十四)_服务器性能监控
下载插件 1.访问网址http://jmeter-plugins.org/downloads/all/,下载三个文件.其中JMeterPlugins-Standard和JMeterPlugins-Ex ...
- Qt5中this application has requested the runtime to terminate it in an unusual way 无法运行问题的解决
在windows平台使用Qt5.8mingw版写出的程序,在Qt中运行正常,而以release的形式编译并且补充完必要的dll文件后,在其他电脑上运行出现了以下问题: 经过查阅许多资料和亲身实验,终于 ...
- css3-------:before和:after的作用
1.:before和:after的作用就是在指定的元素内容(而不是元素本身)之前或者之后插入一个包含content属性指定内容的行内元素,最基本的用法如下: <!doctype html> ...
- Xcode9无线调试教程
Xcode9最让人眼前一亮的莫过于同一局域网下支持无线部署调试. 从Xcode9支持无线部署调试来看,千呼万唤的iPhone8支持无线充电几乎是必然.下面简单梳理下无线调试的步骤: 1. 第一次部署调 ...
- IT轮子系列(三)——如何给返回类型添加注释——Swagger的使用(二)
前言 一般对外提供API,都会统一一个返回类型,比如所有的接口都统一返回HttpResponseMessage.这样当我们在方法上添加///注释时,是无法清楚的知道都返回字段都又那些以及它们的数据类型 ...
- 伸展树--java
文字转载自:http://www.cnblogs.com/vamei 代码转载自:http://www.blogjava.net/javacap/archive/2007/12/19/168627.h ...
- iframe局部刷新的二种实现方法
需求描述: 当页面有一部分是不变的或整个页面的图片很多时,可以考虑使用局部刷新,以提高整体的下载速度与用户体验. 1,iframe实现局部刷新的方法一 复制代码代码示例: <script t ...
- JAVA 创建对象4种方法
java创建对象的几种方式 博客分类: java (1) 用new语句创建对象,这是最常见的创建对象的方法.(2) 运用反射手段,调用java.lang.Class或者java.lang.refl ...
- Day5_模块与包(import)(form......import....)
一个文件中定义了很多模块,然后可以再别的文件中调用这几个模块. #导入模块(import) #1,执行源文件 #2,产生以源文件为基础的全局名称空间.
- 浏览器选择最新IE渲染
<meta http-equiv="X-UA-Compatible" content="IE=edge" />