日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

2018HDU多校训练-3-Problem G. Interstellar Travel

發布時間:2023/11/27 生活经验 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 2018HDU多校训练-3-Problem G. Interstellar Travel 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
鏈接: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(1T10) , denoting the number of test cases.
In each test case, there is an integer n(2n200000) in the first line, denoting the number of planets.
For the next n lines, each line contains 2 integers xi,yi(0xi,yi109) , 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(1pin) , denoting the route you chosen is p1p2...pm?1pm . 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的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。