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中如何简单的重置APP保存的数据
在任意一款APP中,我们可能需要在磁盘上保存一些游戏数据,以便在下一次运行APP时恢复游戏数据. 但是由于在测试阶段,我们需要快速恢复初始状态的游戏数据,该如何做呢? 非常简单,只需要将APP从真机或 ...
- Auto Create Editable Copy Font(Unity3D开发之二十二)
猴子原创,欢迎转载.转载请注明: 转载自Cocos2Der-CSDN,谢谢! 原文地址: http://blog.csdn.net/cocos2der/article/details/48318879 ...
- ruby轻松自删除代码
因为windows的文件删除机制和unix like的不一样,so不保证如下代码能在windows中使用,哪位童鞋帮我在windows中测试一下也好啊! #!/usr/bin/ruby 5.times ...
- Jquery Easing函数库
从jQuery API 文档中可以知道,jQuery自定义动画的函数.animate( properties [, duration] [, easing] [, complete] )有四个参数: ...
- 《JUnit实战(第2版)》读书笔记
第1章 JUnit起步 主要了解JUnit,如何安装.运行JUnit 要点 JUnit4不需要像JUnit3那样extends TestCase类 Junit4基本都是用注解(该书都翻译为注释,但我喜 ...
- python---用户登录程序
需求: 1. 用户登录,判断用户名密码是否正确 2. 密码输入三次不对则锁定账号 3. 锁定账号无法登录 分析: 1. 输入账号,判断账号是否存在,即账号是否在账号文件中存在: 2. 如果账号存在,则 ...
- MDCC2013会议笔记
技术性的Topic听的不多,也没记多少东西. 下面这些是产品设计论坛的笔记: 互联网为实体行业带来:数据驱动,用户参与,快速验证想法 体验整合:线上与线下,产品与服务,运营与营销,用户和利益相关方体验 ...
- Python练习题-1.使用匿名函数对1~1000求和,代码力求简洁。
Python 练习 标签(空格分隔): Python Python练习题 Python知识点 一.使用匿名函数对1~1000求和,代码力求简洁. 答案: In [1]: from functools ...
- jdk的配置
在新建页面系统变量,输入变量名"JAVA_HOME":变量值"你的jdk的路径 在系统变量区域,选择"新建",输入变量名"CLASSPATH ...
- Create R NoteBook require updated versions of the following packages : knitr,rmarkdown.
Create R NoteBook require updated versions of the following packages : knitr,rmarkdown. 点击yes安装失败的时 ...