链接:http://acm.hdu.edu.cn/showproblem.php?pid=6325                                 
                               Interstellar Travel

  

Problem Description
After trying hard for many years, Little Q has finally received an astronaut license. To celebrate the fact, he intends to buy himself a spaceship and make an interstellar travel.
Little Q knows the position of n

planets in space, labeled by 1

to n

. To his surprise, these planets are all coplanar. So to simplify, Little Q put these n

planets on a plane coordinate system, and calculated the coordinate of each planet (xi,yi)

.
Little Q plans to start his journey at the 1

-th planet, and end at the n

-th planet. When he is at the i

-th planet, he can next fly to the j

-th planet only if xi<xj

, which will cost his spaceship xi×yj−xj×yi

units of energy. Note that this cost can be negative, it means the flight will supply his spaceship.
Please write a program to help Little Q find the best route with minimum total cost.

 
Input
The first line of the input contains an integer T(1≤T≤10)

, denoting the number of test cases.
In each test case, there is an integer n(2≤n≤200000)

in the first line, denoting the number of planets.
For the next n

lines, each line contains 2

integers xi,yi(0≤xi,yi≤109)

, denoting the coordinate of the i

-th planet. Note that different planets may have the same coordinate because they are too close to each other. It is guaranteed that y1=yn=0,0=x1<x2,x3,...,xn−1<xn

.

 
Output
For each test case, print a single line containing several distinct integers p1,p2,...,pm(1≤pi≤n)

, denoting the route you chosen is p1→p2→...→pm−1→pm

. Obviously p1

should be 1

and pm

should be n

. You should choose the route with minimum total cost. If there are multiple best routes, please choose the one with the smallest lexicographically.
A sequence of integers a

is lexicographically smaller than a sequence of b

if there exists such index j

that ai=bi

for all i<j

, but aj<bj

.

 
Sample Input
1
3
0 0
3 0
4 0
 
Sample Output
1 2 3
 
Source
 
 
Recommend
chendu
题解:WA了无数发,忘了一句话,“有的星球由于太近可以认为坐标相同,但输出的时候应该输出编号小的”,后来重读了题目,家里个条件就过了; 
这个题目可以转化为凸包问题,只求上凸包,求上凸包时注意排除横坐标相同的点,只取纵坐标大的点,重要的一点:对于纵坐标相同而横坐标不同的点,我们需要判断中间点的编号是否比下一个点大,因为按字典序输出,故如果大于则去掉该点,小于等于则保留,注意细节;
参考代码:
 
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn=2e5+10;
LL vis[maxn],T,n;
LL num[maxn];
struct Point{
LL x,y;
LL id;
Point(double xx=0,double yy=0) : x(xx),y(yy) {}
} p[maxn],ch[maxn];
typedef Point Vector;
Vector operator + (Vector a,Vector b) { return Vector(a.x+b.x,a.y+b.y); }
Vector operator - (Vector a,Vector b) { return Vector(a.x-b.x,a.y-b.y); }
Vector operator * (Vector a,Vector b) { return Vector(a.x*b.x,a.y*b.y); }
Vector operator / (Vector a,Vector b) { return Vector(a.x/b.x,a.y/b.y); }
bool operator < (const Point &a,const Point &b){ return a.x==b.x? (a.y==b.y? a.id<b.id : a.y>b.y) : a.x<b.x ; }
LL Cross(Vector a,Vector b) { return a.x*b.y-a.y*b.x; } void ConvexHull()
{
LL m=0; memset(vis,0,sizeof vis);
for(int i=1;i<=n;i++)
{
if(i>1 && p[i].x == p[i-1].x) continue;
while(m>1 && Cross(ch[m]-ch[m-1],p[i]-ch[m])>0) m--;
ch[++m]=p[i];
} vis[1]=vis[m]=1;
for(int i=2;i<m;i++)
if(Cross(ch[i+1]-ch[i],ch[i]-ch[i-1])!=0) vis[i]=1;
for(int i=m;i>0;i--)
{
if(vis[i]) num[i]=ch[i].id;
else num[i]=min(num[i+1],ch[i].id);
}
for(int i=1;i<m;i++)
if(num[i]==ch[i].id) printf("%lld ",num[i]);
printf("%lld\n",num[m]);
} int main()
{
scanf("%lld",&T);
while(T--)
{
scanf("%lld",&n);
for(int i=1;i<=n;i++) scanf("%lld%lld",&p[i].x,&p[i].y),p[i].id=i;
sort(p+1,p+n+1);
ConvexHull();
}
return 0;
}

  

 
 

2018HDU多校训练-3-Problem G. Interstellar Travel的更多相关文章

  1. HDU 6325 Problem G. Interstellar Travel(凸包)

    题意: 给你n个点,第一个点一定是(0,0),最后一个点纵坐标yn一定是0,中间的点的横坐标一定都是在(0,xn)之间的 然后从第一个点开始飞行,每次飞到下一个点j,你花费的价值就是xi*yj-xj* ...

  2. 2018HDU多校训练-3-Problem M. Walking Plan

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=6331 Walking Plan  Problem Description There are n inte ...

  3. 2018HDU多校训练-3-Problem D. Euler Function

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=6322 Problem Description In number theory, Euler's toti ...

  4. 2018HDU多校训练一 K - Time Zone

    Chiaki often participates in international competitive programming contests. The time zone becomes a ...

  5. 2018HDU多校训练-3-Problem F. Grab The Tree

    Little Q and Little T are playing a game on a tree. There are n vertices on the tree, labeled by 1,2 ...

  6. 2018HDU多校训练一 D Distinct Values

    hiaki has an array of nn positive integers. You are told some facts about the array: for every two e ...

  7. 2018HDU多校训练一 C -Triangle Partition

    Chiaki has 3n3n points p1,p2,-,p3np1,p2,-,p3n. It is guaranteed that no three points are collinear.  ...

  8. 2018HDU多校训练一 A - Maximum Multiple

    Given an integer nn, Chiaki would like to find three positive integers xx, yy and zzsuch that: n=x+y ...

  9. hdu6325 Interstellar Travel 凸包变形

    题目传送门 题目大意: 给出n个平面坐标,保证第一个点和第n个点y值为0,其余点的x坐标都在中间,要从 i 点走到 j 点的要求是 i 点的横坐标严格小于 j 的横坐标,并且消耗的能量是(xi * y ...

随机推荐

  1. Spring 框架常用语法进行总结

    Spring 框架常用语法进行总结: spring框架的二大主要的功能就是IOC和AOP. IOC: 控制反转(依赖注入) AOP: 面向切面编程 学习spring最好的方法就是去看官网,里面有详细的 ...

  2. 总结一下 IEnumerable 的例子

    本篇将围绕 <试试 IEnumerable 的 10 个小例子>和<试试 IEnumerable 的另外 6 个小例子>给出的例子,总结一下对于 IEnumerable 接口的 ...

  3. java中继承,子类是否继承父类的构造函数

    java中继承,子类是否继承父类的构造函数 java继承中子类是不会继承父类的构造函数的,只是必须调用(隐式或者显式) 下面来看例子: public class TestExtends { publi ...

  4. Maven系列第6篇:生命周期和插件详解,此篇看过之后在maven的理解上可以超越同级别90%的人!

    maven系列目标:从入门开始开始掌握一个高级开发所需要的maven技能. 这是maven系列第6篇. 整个maven系列的内容前后是有依赖的,如果之前没有接触过maven,建议从第一篇看起,本文尾部 ...

  5. nyoj 264-国王的魔镜 (string[-1:-int(str_len/2+1):-1])

    264-国王的魔镜 内存限制:64MB 时间限制:3000ms 特判: No 通过数:13 提交数:25 难度:1 题目描述: 国王有一个魔镜,可以把任何接触镜面的东西变成原来的两倍——只是,因为是镜 ...

  6. 【SSM Spring 线程池 OJ】 使用Spring线程池ThreadPoolTaskExecutor

    最近做的Online Judge项目,在本地判题的实现过程中,遇到了一些问题,包括多线程,http通信等等.现在完整记录如下: OJ有一个业务是: 用户在前端敲好代码,按下提交按钮发送一个判题请求给后 ...

  7. RAID5创建流程(3块做RAID,两块备份)

    https://www.cnblogs.com/meng-yu37/p/11739680.html(raid10链接) RAID5和RAID10 配置差不多,这里只指出不同的地方, 2. 使用mdad ...

  8. 结合源码,重温 Android View 的事件处理知多少 ?

    前言 Android View 的 事件处理在我们的编程中,可谓是无处不在了.但对于大多数人而言,一直都是简单的使用,对其原理缺乏深入地认识. 学 Android 有一段时间了,最近发现,很多基础知识 ...

  9. JavaScript返回格式化的时间字符串

    http://www.w3school.com.cn/jsref/jsref_getMinutes.asp 由 getMinutes() 返回的值是一个两位的数字.不过返回值不总是两位的,如果该值小于 ...

  10. 网站统计IP PV UV

    ###我只是一个搬运工 网站流量统计可以帮助我们分析网站的访问和广告来访等数据,里面包含很多数据的,比如访问使用的系统,浏览器,ip归属地,访问时间,搜索引擎来源,广告效果等. PV(访问量):Pag ...