首页 技术 正文
技术 2022年11月19日
0 收藏 512 点赞 4,955 浏览 3093 个字

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

  

Problem DescriptionAfter 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 n2018HDU多校训练-3-Problem G.     Interstellar Travel

planets in space, labeled by 12018HDU多校训练-3-Problem G.     Interstellar Travel

to n2018HDU多校训练-3-Problem G.     Interstellar Travel

. To his surprise, these planets are all coplanar. So to simplify, Little Q put these n2018HDU多校训练-3-Problem G.     Interstellar Travel

planets on a plane coordinate system, and calculated the coordinate of each planet (x2018HDU多校训练-3-Problem G.     Interstellar Traveli2018HDU多校训练-3-Problem G.     Interstellar Travel,y2018HDU多校训练-3-Problem G.     Interstellar Traveli2018HDU多校训练-3-Problem G.     Interstellar Travel)2018HDU多校训练-3-Problem G.     Interstellar Travel

.
Little Q plans to start his journey at the 12018HDU多校训练-3-Problem G.     Interstellar Travel

-th planet, and end at the n2018HDU多校训练-3-Problem G.     Interstellar Travel

-th planet. When he is at the i2018HDU多校训练-3-Problem G.     Interstellar Travel

-th planet, he can next fly to the j2018HDU多校训练-3-Problem G.     Interstellar Travel

-th planet only if x2018HDU多校训练-3-Problem G.     Interstellar Traveli2018HDU多校训练-3-Problem G.     Interstellar Travel<x2018HDU多校训练-3-Problem G.     Interstellar Travelj2018HDU多校训练-3-Problem G.     Interstellar Travel2018HDU多校训练-3-Problem G.     Interstellar Travel

, which will cost his spaceship x2018HDU多校训练-3-Problem G.     Interstellar Traveli2018HDU多校训练-3-Problem G.     Interstellar Travel×y2018HDU多校训练-3-Problem G.     Interstellar Travelj2018HDU多校训练-3-Problem G.     Interstellar Travel−x2018HDU多校训练-3-Problem G.     Interstellar Travelj2018HDU多校训练-3-Problem G.     Interstellar Travel×y2018HDU多校训练-3-Problem G.     Interstellar Traveli2018HDU多校训练-3-Problem G.     Interstellar Travel2018HDU多校训练-3-Problem G.     Interstellar Travel

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. InputThe first line of the input contains an integer T(1≤T≤10)2018HDU多校训练-3-Problem G.     Interstellar Travel

, denoting the number of test cases.
In each test case, there is an integer n(2≤n≤200000)2018HDU多校训练-3-Problem G.     Interstellar Travel

in the first line, denoting the number of planets.
For the next n2018HDU多校训练-3-Problem G.     Interstellar Travel

lines, each line contains 22018HDU多校训练-3-Problem G.     Interstellar Travel

integers x2018HDU多校训练-3-Problem G.     Interstellar Traveli2018HDU多校训练-3-Problem G.     Interstellar Travel,y2018HDU多校训练-3-Problem G.     Interstellar Traveli2018HDU多校训练-3-Problem G.     Interstellar Travel(0≤x2018HDU多校训练-3-Problem G.     Interstellar Traveli2018HDU多校训练-3-Problem G.     Interstellar Travel,y2018HDU多校训练-3-Problem G.     Interstellar Traveli2018HDU多校训练-3-Problem G.     Interstellar Travel≤102018HDU多校训练-3-Problem G.     Interstellar Travel92018HDU多校训练-3-Problem G.     Interstellar Travel)2018HDU多校训练-3-Problem G.     Interstellar Travel

, denoting the coordinate of the i2018HDU多校训练-3-Problem G.     Interstellar Travel

-th planet. Note that different planets may have the same coordinate because they are too close to each other. It is guaranteed that y2018HDU多校训练-3-Problem G.     Interstellar Travel12018HDU多校训练-3-Problem G.     Interstellar Travel=y2018HDU多校训练-3-Problem G.     Interstellar Traveln2018HDU多校训练-3-Problem G.     Interstellar Travel=0,0=x2018HDU多校训练-3-Problem G.     Interstellar Travel12018HDU多校训练-3-Problem G.     Interstellar Travel<x2018HDU多校训练-3-Problem G.     Interstellar Travel22018HDU多校训练-3-Problem G.     Interstellar Travel,x2018HDU多校训练-3-Problem G.     Interstellar Travel32018HDU多校训练-3-Problem G.     Interstellar Travel,…,x2018HDU多校训练-3-Problem G.     Interstellar Traveln−12018HDU多校训练-3-Problem G.     Interstellar Travel<x2018HDU多校训练-3-Problem G.     Interstellar Traveln2018HDU多校训练-3-Problem G.     Interstellar Travel2018HDU多校训练-3-Problem G.     Interstellar Travel

. OutputFor each test case, print a single line containing several distinct integers p2018HDU多校训练-3-Problem G.     Interstellar Travel12018HDU多校训练-3-Problem G.     Interstellar Travel,p2018HDU多校训练-3-Problem G.     Interstellar Travel22018HDU多校训练-3-Problem G.     Interstellar Travel,…,p2018HDU多校训练-3-Problem G.     Interstellar Travelm2018HDU多校训练-3-Problem G.     Interstellar Travel(1≤p2018HDU多校训练-3-Problem G.     Interstellar Traveli2018HDU多校训练-3-Problem G.     Interstellar Travel≤n)2018HDU多校训练-3-Problem G.     Interstellar Travel

, denoting the route you chosen is p2018HDU多校训练-3-Problem G.     Interstellar Travel12018HDU多校训练-3-Problem G.     Interstellar Travel→p2018HDU多校训练-3-Problem G.     Interstellar Travel22018HDU多校训练-3-Problem G.     Interstellar Travel→…→p2018HDU多校训练-3-Problem G.     Interstellar Travelm−12018HDU多校训练-3-Problem G.     Interstellar Travel→p2018HDU多校训练-3-Problem G.     Interstellar Travelm2018HDU多校训练-3-Problem G.     Interstellar Travel2018HDU多校训练-3-Problem G.     Interstellar Travel

. Obviously p2018HDU多校训练-3-Problem G.     Interstellar Travel12018HDU多校训练-3-Problem G.     Interstellar Travel2018HDU多校训练-3-Problem G.     Interstellar Travel

should be 12018HDU多校训练-3-Problem G.     Interstellar Travel

and p2018HDU多校训练-3-Problem G.     Interstellar Travelm2018HDU多校训练-3-Problem G.     Interstellar Travel2018HDU多校训练-3-Problem G.     Interstellar Travel

should be n2018HDU多校训练-3-Problem G.     Interstellar Travel

. 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 a2018HDU多校训练-3-Problem G.     Interstellar Travel

is lexicographically smaller than a sequence of b2018HDU多校训练-3-Problem G.     Interstellar Travel

if there exists such index j2018HDU多校训练-3-Problem G.     Interstellar Travel

that a2018HDU多校训练-3-Problem G.     Interstellar Traveli2018HDU多校训练-3-Problem G.     Interstellar Travel=b2018HDU多校训练-3-Problem G.     Interstellar Traveli2018HDU多校训练-3-Problem G.     Interstellar Travel2018HDU多校训练-3-Problem G.     Interstellar Travel

for all i<j2018HDU多校训练-3-Problem G.     Interstellar Travel

, but a2018HDU多校训练-3-Problem G.     Interstellar Travelj2018HDU多校训练-3-Problem G.     Interstellar Travel<b2018HDU多校训练-3-Problem G.     Interstellar Travelj2018HDU多校训练-3-Problem G.     Interstellar Travel2018HDU多校训练-3-Problem G.     Interstellar Travel

. Sample Input1
3
0 0
3 0
4 0 Sample Output1 2 3 Source2018 Multi-University Training Contest 3  Recommendchendu题解: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;
}

  

  

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,992
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,506
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,349
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,134
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,767
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,844