POJ 1696 Space Ant(凸包变形)
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
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std; const double EPS = 1e-; inline int sgn(double x) {
return (x > EPS) - (x < -EPS);
} struct Point {
double x, y;
Point() {}
Point(double x, double y): x(x), y(y) {}
void read() {
scanf("%lf%lf", &x, &y);
}
bool operator < (const Point &rhs) const {
if(y != rhs.y) return y < rhs.y;
return x < rhs.x;
}
Point operator + (const Point &rhs) const {
return Point(x + rhs.x, y + rhs.y);
}
Point operator - (const Point &rhs) const {
return Point(x - rhs.x, y - rhs.y);
}
Point operator * (const int &b) const {
return Point(x * b, y * b);
}
Point operator / (const int &b) const {
return Point(x / b, y / b);
}
double length() const {
return sqrt(x * x + y * y);
}
Point unit() const {
return *this / length();
}
};
typedef Point Vector; double dist(const Point &a, const Point &b) {
return (a - b).length();
} double across(const Point &a, const Point &b) {
return a.x * b.y - a.y * b.x;
}
//turn left
bool cross(const Point &sp, const Point &ed, const Point &op) {
return sgn(across(sp - op, ed - op)) > ;
} /*******************************************************************************************/ const int MAXN = ; Point p[MAXN];
bool del[MAXN];
int n, T; void solve() {
memset(del, , sizeof(del));
int last = ;
for(int i = ; i < n; ++i)
if(p[i] < p[last]) last = i;
for(int i = ; i < n; ++i) {
printf(" %d", last + );
del[last] = true;
int t = ;
for(t = ; t < n; ++t) if(!del[t]) break;
for(int j = ; j < n; ++j) {
if(del[j] || j == t) continue;
if(cross(p[j], p[t], p[last])) t = j;
}
last = t;
}
} int main() {
scanf("%d", &T);
while(T--) {
scanf("%d", &n);
int t;
for(int i = ; i < n; ++i)
scanf("%d", &t), p[i].read();
printf("%d", n);
solve();
puts("");
}
}
POJ 1696 Space Ant(凸包变形)的更多相关文章
- POJ 1696 - Space Ant 凸包的变形
Technorati Tags: POJ,计算几何,凸包 初学计算几何,引入polygon后的第一个挑战--凸包 此题可用凸包算法做,只要把压入凸包的点从原集合中排除即可,最终形成图形为螺旋线. 关于 ...
- poj 1696 Space Ant (极角排序)
链接:http://poj.org/problem?id=1696 Space Ant Time Limit: 1000MS Memory Limit: 10000K Total Submissi ...
- 2018.07.04 POJ 1696 Space Ant(凸包卷包裹)
Space Ant Time Limit: 1000MS Memory Limit: 10000K Description The most exciting space discovery occu ...
- poj 1696:Space Ant(计算几何,凸包变种,极角排序)
Space Ant Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 2876 Accepted: 1839 Descrip ...
- POJ 1696 Space Ant 卷包裹法
Space Ant Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 3316 Accepted: 2118 Descrip ...
- POJ 1696 Space Ant(极角排序)
Space Ant Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 2489 Accepted: 1567 Descrip ...
- poj 1696 Space Ant(模拟+叉积)
Space Ant Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 3840 Accepted: 2397 Descrip ...
- POJ 1696 Space Ant(点积的应用)
Space Ant 大意:有一仅仅蚂蚁,每次都仅仅向当前方向的左边走,问蚂蚁走遍全部的点的顺序输出.開始的点是纵坐标最小的那个点,開始的方向是開始点的x轴正方向. 思路:从開始点開始,每次找剩下的点中 ...
- 简单几何(凸包) POJ 1696 Space Ant
题目传送门 题意:一个蚂蚁一直往左边走,问最多能走多少步,且输出路径 分析:就是凸包的变形题,凸包性质,所有点都能走.从左下角开始走,不停排序.有点纠结,自己的凸包不能AC.待理解透凸包再来写.. 好 ...
随机推荐
- 06JavaScript变量
JavaScript 变量 变量是用于存储信息的"容器". var x=5; var y=6; var z=x+y; 就像代数那样 x=5 y=6 z=x+y 在代数中,我们使用字 ...
- fastdfs安装过程
Fastdfs于centos7的安装步骤(支持横向拓展) 主要目的:根据网上教程搭建时遇到的问题以及描述不明确的地方进行补充和说明 一.首先需要准备以下4个文件 nginx-1.12.0.tar.gz ...
- 【设计模式】Java之单例设计模式
1.单例设计模式:一个类只能有一个对象 1.1 创建单例类的步骤: 1.将构造方法私有化 2.创建私有的静态成员变量 3.共有的静态成员方法,提供当前的唯一对象 1.1 创建单例的两种方式: 1.饿汉 ...
- JavaScript6里出现了哪些新语法、新特征?
ES5是2009年就出来的,目前来说在我写这篇文章的时候基本上ES6在浏览器上面还没有普及,不过Google浏览器是支持ES6语法的,谁让Google是美国生产的呢... ES6现在使用的地方其实还是 ...
- Bigdata--hadoop系列安装
Date:20180827 Monday 目前市场hadoop主流版本是2.7.x系列,下面我们就以hadoop-2.7.3为例进行安装 安装前准备: 1.操作系统:cetos(6和7) 2.java ...
- Hadoop-Hive学习笔记(2)
1.Hive基本操作 #创建数据库hive>create database name;#创建新表hive> create table students(id int,name string ...
- python学习——面向对象的三大特性
一.继承 继承是一种创建新类的方式,在python中,新建的类可以继承一个或多个父类,父类又可称为基类或超类,新建的类称为派生类或子类. 1.python中类的继承分为:单继承和多继承 class P ...
- Shuffling Machine
7-43 Shuffling Machine(20 分) Shuffling is a procedure used to randomize a deck of playing cards. Bec ...
- (数据科学学习手札44)在Keras中训练多层感知机
一.简介 Keras是有着自主的一套前端控制语法,后端基于tensorflow和theano的深度学习框架,因为其搭建神经网络简单快捷明了的语法风格,可以帮助使用者更快捷的搭建自己的神经网络,堪称深度 ...
- [Real World Haskell翻译]第22章 扩展示例:Web客户端编程
第22章 扩展示例:Web客户端编程 至此,您已经看到了如何与数据库交互,解析一些数据,以及处理错误.现在让我们更进了一步,引入Web客户端库的组合. 在本章,我们将开发一个真正的应用程序:一个播客下 ...