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
,y
i
)
.
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
<x
j
, which will cost his spaceship xi
×y
j
−x
j
×y
i
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
,y
i
(0≤x
i
,y
i
≤10
9
)
, 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
=y
n
=0,0=x
1
<x
2
,x
3
,...,x
n−1
<x
n
.
, denoting the route you chosen is p1
→p
2
→...→p
m−1
→p
m
. 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
=b
i
for all i<j
, but aj
<b
j
.
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 ...
随机推荐
- [ PyQt入门教程 ] PyQt5中数据表格控件QTableWidget使用方法
如果你想让你开发的PyQt5工具展示的数据显得整齐.美观.好看,显得符合你的气质,可以考虑使用QTableWidget控件.之前一直使用的是textBrowser文本框控件,数据展示还是不太美观.其中 ...
- Ubuntu 16.04.4 安装openjdk各种问题
不知道为什么会如此曲折,一个问题接一个,如果你也遇到问题,可以参考参考 问题1:......has no installation andidate,解决如下(不理解): 参考https://asku ...
- ArcGIS API For Javascript :读取 CSV 文件的方法
我们临时会遇到一些测试数据,通常从数据库中以 CSV 格式导出.最简单实用的方法就是使用 ajax 去读取文件,记得引入 jQuery . 例如,在<ArcGIS JS API :新增一个热力图 ...
- 记录工作遇到的死锁问题(Lock wait timeout exceeded; try restarting transaction)
1.问题背景 刚来新公司不久,对业务还不太熟悉,所以领导先安排我维护原有系统.大概介绍下项目背景,项目分为核心业务部分在项目A中,与第三方交互的业务在项目B中,前端发起请求调用A项目接口,并在A项目中 ...
- opencv 5 图像转换(2 霍夫变换)
霍夫线变换 标准霍夫变换和多尺度霍夫变换(HoughLines()函数) 实例: #include <opencv2/opencv.hpp> #include <opencv2/im ...
- Bootstrap3中的affix的使用Demo
<div class="container"> <div class="col-md-3"> <ul class="li ...
- jinjia2
ansible-playbook --become --become-method=su -K copy.yml - hosts: web remote_user: ansible tasks: - ...
- node 后台使用增删改查(4)
无论node还是java增删改查都是一样的原理,变得是配合框架使用时候有简便方法而已. 这里我接着上一篇开始讲,使用同一个数据库(数据库创建)这里必须创建了数据库 优化:为了维护方便这里我们把sql语 ...
- 【Luogu P3376】网络最大流
Luogu P3376 最大流是网络流模型的一个基础问题. 网络流模型就是一种特殊的有向图. 概念: 源点:提供流的节点(入度为0),类比成为一个无限放水的水厂 汇点:接受流的节点(出度为0),类比成 ...
- BeanUtils.copyProperties()怎样去掉字段首尾的空格
背景 下午三时许,笔者正戴着耳机听着歌开心的敲着bug,忽然听到办公室的吵架声,原来是ios开发和产品小姐姐吵起来了,为了一个车牌号的校验问题.起因是ios传的车牌号没有将字符串的首尾空格去掉,后端直 ...