链接: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
2018 Multi-University Training Contest 3
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;
}

  

转载于:https://www.cnblogs.com/songorz/p/9398507.html

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. 【杭电多校round3】G Interstellar Travel

    题意 给定二维平面上的n个点,保证只有一个点(P_1)横坐标最小,一个点横坐标最大(P_n),在坐标轴上其余点无序且可能重合 即 y_1=y_n=0, 0=x_1<x_2,x_3,...,x_n ...

  3. 2018 Multi-University Training Contest 3: G. Interstellar Travel(凸包)

    题意:给你平面上n个点,第一个点一定在(0, 0),第n个点的y坐标一定为0,除此之外中间所有点的x坐标一定大于0且小于最后一个点的x坐标,你从一号点开始出发,中间从第i个点到第j个点必须满足xj&g ...

  4. Western Subregional of NEERC, Minsk, Wednesday, November 4, 2015 Problem G. k-palindrome dp

    Problem G. k-palindrome 题目连接: http://opentrains.snarknews.info/~ejudge/team.cgi?SID=c75360ed7f2c7022 ...

  5. Problem G. Pandaria(线段树合并 + Kruskal 重构树)

    Problem G. Pandaria 给定一个有nnn条边的无向连通图,每条边有对应的边权,每个点有一个颜色, 问从一个点出发,经过不超过www的边权,所能到达的点中,颜色出现次数做多且颜色编号最小 ...

  6. Problem G: 函数---判断日期(年月日)是否合法

    Problem G: 函数---判断日期(年月日)是否合法 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 566  Solved: 240 Descr ...

  7. Problem G: C语言习题 医生值班

    Problem G: C语言习题 医生值班 Time Limit: 3 Sec  Memory Limit: 128 MB Submit: 847  Solved: 102 [Submit][Stat ...

  8. “玲珑杯”郑州轻工业学院第八届ACM程序设计大赛Problem G: 蛤玮点菜

    Problem G: 蛤玮点菜 Time Limit: 2 Sec  Memory Limit: 128 MB Submit: 320  Solved: 31 SubmitWeb Board Desc ...

  9. HDU6578 2019HDU多校训练赛第一场 1001 (dp)

    HDU6578 2019HDU多校训练赛第一场 1001 (dp) 传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6578 题意: 你有n个空需要去填,有 ...

最新文章

  1. 这个能快速发表Cell,Nature,Molecular cell的分析技术你要错过吗?
  2. 从源码分析DEARGUI之动态绘图的两种方法
  3. [arm 驱动]Linux输入子系统分析
  4. java获取注解信息_java 自定义注解,获取注解信息
  5. 拉勾启源老师mysql讲义,【拉勾教育数据分析实战训练营】--Tableau学习笔记-重点回顾1...
  6. ant react 上传_react之ant design mobile如何只能上传一张图片
  7. 防火墙(9)——禁止某个时间段内访问我们的web
  8. docker启动后自动退出_Spring Boot项目启动后如何自动执行逻辑
  9. kubevirt在360的探索之路(k8s接管虚拟化)
  10. ES+Redis+MySQL,这个高可用架构设计太顶了!
  11. Raki的统计学习方法笔记0x1章:统计学习及监督学习概论
  12. 如何用HTML语言设计进度条,html进度条代码_html5如何实现简单进度条效果
  13. vb.net 教程 5-19 拓展:制作一个QQ大家来找茬和美女找茬辅助工具
  14. 如何申请微信公众平台帐号
  15. IO流总结(基础知识)
  16. 数据库系统原理(一)引言
  17. uniapp ios原生插件开发之插件包格式(package.json)
  18. 圆形体癣是什么样子的图片_【圆圈状的癣不痛不痒】_原因_起因-大众养生网
  19. Tekla钢结构二次开发 第5节正交梁、螺旋梁以及工作平面
  20. Netty的编解码器

热门文章

  1. 数据库中自定义排序规则,Mysql中自定义字段排序规则,Oracle中自定义字段排序规则,decode函数的用法,field函数的用法
  2. Spring Boot整合Spring Data JPA操作数据
  3. 用伪代码模拟洗衣机的运转流程
  4. Git 常用操作(6)- 推送到远程仓库(git push)删除远程分支(git push origin --delete)
  5. 难忘的一天——装操作系统(四)
  6. starrocks问题小结
  7. Tensorflow会话
  8. Map再整理,从底层源码探究HashMap
  9. 鸿蒙OS:万物互联,方舟Compiler
  10. 华为+长安研发芯片?长安蔚来更名“阿维塔科技”