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 ...
随机推荐
- SpriteBuilder中锚点的一般用法
注意:改变节点的锚点(anchor point)将会影响缩放和旋转操作,也会影响边界边框和碰撞的检测. 锚点仅仅挪动节点的视觉表现,这种改变可能与物理表现不一致. 你绝不应该错误的挪动锚点去改变节点的 ...
- ffdshow 源代码分析 3: 位图覆盖滤镜(设置部分Settings)
===================================================== ffdshow源代码分析系列文章列表: ffdshow 源代码分析 1: 整体结构 ffds ...
- pop弹簧动画实现
POP是一个在iOS与OS X上通用的极具扩展性的动画引擎.它在基本的静态动画的基础上增加的弹簧动画与衰减动画,使之能创造出更真实更具物理性的交互动画.POP的API可以快速的与现有的ObjC代码集成 ...
- jQuery如何停止元素的animate动画,还有怎样判断是否处于动画状态
jquery的animation会自动进入队列,就出现了一个问题,这些动画会一一执行完成,而我们实际的本意是当鼠标移开的时候动画即终止. 停止元素的动画方法:stop()语法结构:stop([clea ...
- <mate name="viewport">移动端设置详解
<meta name="viewport" content="width=device-width,height=device-height,initial-sca ...
- javascript初学者必须注意的7个细节
[IT168 技术]每种语言都有它特别的地方,对于JavaScript来说,使用var就可以声明任意类型的变量,这门脚本语言看起来很简单,然而想要写出优雅的代码却是需要不断积累经验的.本文列举Java ...
- JAVA设计模式--学习总结(序)
设计模式(Design pattern)是一套被反复使用的.代码设计经验的总结.使用设计模式是为了可重用代码.让代码更容易被他人理解.保证代码可靠性. 常见的设计模式有23种.分为三大类:创建型模式, ...
- php namespace与use
实验代码 ~/aa.php ~/bb.php 1.命名空间与文件加载的关系 本人在命名空间与文件加载上一直有一个误区,用了命名空间文件不用加载了? 实验1:去掉requre语句 可以看到就算使用命名空 ...
- win10右键添加在此处打开powershell
如图: 你想要的效果可能就是这个吧?但是找了好久没有找到方法?爸比告诉你,不需要修改任何东西, 解锁新姿势: 在文件夹空白处,按住shift同时鼠标右击,发现没??发现没!!!!
- C#避免踩坑之如何添加paint事件
看截图: 首先,右击->属性 然后出来这个界面. 接下来,注意看这个界面的上面:鼠标悬停这个闪电符号,看到没,事件!! 那个闪电符号,点它! 然后下拉找到这个: 你要事先在代码里面添加Form1 ...