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 ...
随机推荐
- centos6官网镜像dvd1和dvd2的解释
- Maven系列第8篇:你的maven项目构建太慢了,我实在看不下去,带你一起磨刀!!多数使用maven的人都经常想要的一种功能,但是大多数人都不知道如何使用!!!
maven系列目标:从入门开始开始掌握一个高级开发所需要的maven技能. 这是maven系列第8篇. 整个maven系列的内容前后是有依赖的,如果之前没有接触过maven,建议从第一篇看起,本文尾部 ...
- suseoj 1207: 大整数的乘法(java, 大数相乘, C/C++, 大数相乘)
1207: 大整数的乘法 时间限制: 1 Sec 内存限制: 128 MB提交: 7 解决: 2[提交][状态][讨论版][命题人:liyuansong] 题目描述 求两个不超过200位的非负整数 ...
- django_0:项目流程
1.django-admin(.py) startproject mysite——创建项目project 得到__init__.py(说明工程以包结构存在) settings.py(当前工程的一些配置 ...
- ThreadLocal线程局部变量的使用
ThreadLocal: 线程局部变量 一).ThreadLocal的引入 用途:是解决多线程间并发访问的方案,不是解决数据共享的方案. 特点:每个线程提供变量的独立副本,所有的线程使用同一个Thre ...
- 都是为了生活组——‘’都是为了吃饭”微信小程序评价
基于NABCD评论作品,及改进建议 1.根据NABCD评论,作品的选题 N(Need,需求) 纠结症是目前在年轻人身上普遍存在着的问题,食堂食物众多,每次在吃饭前都要纠结好久,大大浪费了时间,还容易产 ...
- element 根据某多个属性合并列
日常渲染 methods: { arraySpanMethod({ row, column, rowIndex, columnIndex }) { // 没办法循环判断具体是那一列 所以就只好写了多个 ...
- 新闻实时分析系统Hive与HBase集成进行数据分析
(一)Hive 概述 (二)Hive在Hadoop生态圈中的位置 (三)Hive 架构设计 (四)Hive 的优点及应用场景 (五)Hive 的下载和安装部署 1.Hive 下载 Apache版本的H ...
- Mysql查询语句之排序查询
语法: /* select 查询列表 from 表 [where 筛选条件] order by 排序列表 [asc/desc] */ ①asc为升序,desc为降序,且默认为升序 ②order by子 ...
- Redis开发与运维:SDS与embstr、raw 深入理解
对于上一篇文章,我又自己总结归纳并补充了一下,有了第二篇. 概览 <<左移 开始之前,我们先准备点东西:位运算 i<<n 总结为 i*2^n 所以 1<<5 = 2 ...