2018HDU多校训练-3-Problem G. 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.
, 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
.
, 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
.
3
0 0
3 0
4 0
#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的更多相关文章
- HDU 6325 Problem G. Interstellar Travel(凸包)
题意: 给你n个点,第一个点一定是(0,0),最后一个点纵坐标yn一定是0,中间的点的横坐标一定都是在(0,xn)之间的 然后从第一个点开始飞行,每次飞到下一个点j,你花费的价值就是xi*yj-xj* ...
- 2018HDU多校训练-3-Problem M. Walking Plan
链接:http://acm.hdu.edu.cn/showproblem.php?pid=6331 Walking Plan Problem Description There are n inte ...
- 2018HDU多校训练-3-Problem D. Euler Function
链接:http://acm.hdu.edu.cn/showproblem.php?pid=6322 Problem Description In number theory, Euler's toti ...
- 2018HDU多校训练一 K - Time Zone
Chiaki often participates in international competitive programming contests. The time zone becomes a ...
- 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 ...
- 2018HDU多校训练一 D Distinct Values
hiaki has an array of nn positive integers. You are told some facts about the array: for every two e ...
- 2018HDU多校训练一 C -Triangle Partition
Chiaki has 3n3n points p1,p2,-,p3np1,p2,-,p3n. It is guaranteed that no three points are collinear. ...
- 2018HDU多校训练一 A - Maximum Multiple
Given an integer nn, Chiaki would like to find three positive integers xx, yy and zzsuch that: n=x+y ...
- hdu6325 Interstellar Travel 凸包变形
题目传送门 题目大意: 给出n个平面坐标,保证第一个点和第n个点y值为0,其余点的x坐标都在中间,要从 i 点走到 j 点的要求是 i 点的横坐标严格小于 j 的横坐标,并且消耗的能量是(xi * y ...
随机推荐
- vue2获取dom节点
vue2.*版本中 在标签中加上ref='dom',然后在代码中this.$refs.dom这样就拿到了页面元素 例如:<div class='box' ref='myBox'>你好< ...
- 微信 AES 解密报错 Illegal key size 三种解决办法
微信 AES 解密报错 Illegal key size Java 环境 java version "1.8.0_151" Java(TM) SE Runtime Environm ...
- SQL Server 2014:在修改表的内容时,提示“此单元格已更改,尚未将更改提交到数据库”,怎么处理?
那一行上的属性为“不允许为null”的所有字段都填上对应信息,按回车键或者点击下一行任意一个单元格便会自动将更改的信息提交到数据库.
- 服务器上传文件到oss,以及备份
公司的前端js,css是发布到oss的,所以要求后台在发布的同时先把即将要覆盖的文件备份到服务器上 步骤是先上传文件到服务器,服务器上传到oss服务器之前先备份相同文件名的文件 public clas ...
- Bootstrap——导航条(navbar)
导航条和导航从外观上差别不是太多,但在实际使用中导航条要比导航复杂得多. 导航条(navbar)中有一个背景色.而且导航条可以是纯链接(类似导航).表单以及表单和导航一起结合等多种形式. 在制作一个基 ...
- BootStrap中的collapse插件堆叠效果
通过网络上的一系列查找,总结出的collapse插件堆叠效果(网上没有找到,只能自己弄了,帮助那些和我遇到一样状况的同学) 首先感谢一位网友的知识总结给了我灵感,在这里先帮他推荐一波(https:// ...
- Vue项目使用CSS变量实现主题化
主题化管理经常能在网站上看到,一般的思路都是将主题相关的CSS样式独立出来,在用户选择主题的时候加载相应的CSS样式文件.现在大部分浏览器都能很好的兼容CSS变量,主题化样式更容易管理了.最近,使用C ...
- 一个自动修正数据时间和补全缺失数据的MapReduce程序
原始数据如下图: 程序: Mapper类: public class DemoMapper extends Mapper<LongWritable,Text,IntWritable,Text&g ...
- Orleans 3.0 为我们带来了什么
原文:https://devblogs.microsoft.com/dotnet/orleans-3-0/ 作者:Reuben Bond,Orleans首席软件开发工程师 翻译:艾心 这是一篇来自Or ...
- selenium针对浏览器滚动条的操作
我们在实际自动化测试过程中,肯定会遇到当前页面显示不到我们定位的元素.这就需要下拉滚动条才能显示出我们的元素: 而滚动条的按钮又是我们定位不到的,所以需要使用js脚本来完成: 1.先来说我们的下拉滚动 ...