2018 Multi-University Training Contest 3 1007 / hdu6325 Problem G. Interstellar Travel 鍑稿寘

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2018 Multi-University Training Contest 3 1007 / hdu6325 Problem G. Interstellar Travel 鍑稿寘相关的知识,希望对你有一定的参考价值。

鏍囩锛?a href='http://www.mamicode.com/so/1/%e8%a1%a5%e5%85%a8' title='琛ュ叏'>琛ュ叏   point   璧风偣   nlog   else   淇濈暀   璺緞   typedef   浠g爜   

Problem G. Interstellar Travel

棰樻剰锛?br /> 缁欏畾骞抽潰涓妌涓偣锛岃捣鐐? 涓?0,0)锛岀粓鐐?n 涓?Xn, 0)锛屽叾瀹冪偣鐨勬í鍧愭爣 0 <Xi<Xn锛岀旱鍧愭爣 Xi >=0銆傛瘡娆″彲浠ラ鍒颁竴涓í鍧愭爣涓ユ牸鏇村ぇ鐨勭偣锛屼唬浠蜂负涓や釜鍧愭爣鐨勫弶绉€傛眰璧风偣鍒扮粓鐐规€讳唬浠锋渶灏忕殑椋炶璺嚎锛屽苟杈撳嚭瀛楀吀搴忔渶灏忕殑璺嚎銆?鈮鈮?00000銆?Shortest judge solution: 979 bytes
棰樿В锛?br /> 鏄剧劧鍧愭爣鐩稿悓鐨勭偣閲屽彧淇濈暀缂栧彿鏈€灏忕殑鐐规渶浼樸€?br /> 灏嗚捣鐐瑰埌缁堢偣鐨勮矾寰勮ˉ鍏ㄤ负缁堢偣寰€涓嬭蛋鍒版棤绌疯繙澶勶紝鍐嶅線宸﹁蛋鍒拌捣鐐规涓嬫柟锛屽啀寰€涓婂洖鍒拌捣鐐广€?br /> 浠绘剰璺緞涓洖鍒拌捣鐐归儴鍒嗙殑浠d环鐩稿悓锛岃瀵熶唬浠峰拰鐨勫嚑浣曟剰涔夛紝灏辨槸璧拌繃閮ㄥ垎鐨勯潰绉殑鐩稿弽鏁般€?br /> 浠d环鍜屾渶灏忕瓑浠蜂簬闈㈢Н鏈€澶э紝鏁呬竴瀹氭槸娌跨潃涓婂嚫澹宠璧般€?br /> 鏄剧劧璧风偣銆佺粓鐐广€佸嚫澹崇殑鎷愮偣蹇呴』瑕佷綔涓洪檷钀界偣銆?br /> 瀵逛簬鍏辩嚎鐨勭偣a1,a2,...,am锛岃嫢涓€涓偣i鐨勭紪鍙锋槸[i,m]涓渶灏忕殑锛岄偅涔堝湪姝ゅ闄嶈惤鍙互鏈€灏忓寲瀛楀吀搴忋€傛椂闂村鏉傚害O(nlogn)銆?br />

1銆佸叾瀹為鍏堣鏄庣‘浠庣偣1 鐩存帴鍒扮偣 n 鐨勮姳璐规槸 0锛屾墍浠ュ啀鍔犲叆鍏跺畠鐐圭殑浠d环蹇呴』涓鸿礋銆?br /> 2銆佹牴鎹弶绉殑鍑犱綍鎰忎箟锛岄潰绉鏈€澶э紝閭e氨鏄眰鍑稿寘銆?br /> 3銆佹渶鐨殑鏄瀛楀吀搴忔渶灏忚緭鍑猴紝涔熷氨鏄湪鍑稿寘杈圭晫绾夸笂鐨勭偣涔熸湁鍙兘瑕佸彇銆傛墍浠ユ垜浠褰曚竴涓嬭竟鐣岀嚎涓婄殑鐐规槸鍚﹀皬浜庡畠鍒版嫄鐐逛箣闂寸殑鐐广€?/p>


#include<bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
#define rep(i,a,b) for (int i=a; i<=b; ++i)
#define per(i,b,a) for (int i=b; i>=a; --i)
#define mes(a,b)  memset(a,b,sizeof(a))
#define INF 0x3f3f3f3f
#define MP make_pair
#define PB push_back
#define fi  first
#define se  second
typedef long long ll;
const int N = 200005;

struct Point {
    ll  x, y;  int id;
    Point(ll x=0, ll y=0):x(x),y(y){} //鏋勯€犲嚱鏁帮紝鏂逛究浠g爜缂栧啓
};
typedef Point Vector;
Vector operator +(Vector A, Vector B){ return Vector(A.x+B.x, A.y+B.y); }
Vector operator -(Point A, Point B){ return Vector(A.x-B.x, A.y-B.y); }
bool operator <(const Point& a, const Point& b){
    if(a.x==b.x && a.y==b.y) return a.id < b.id;
    return a.x<b.x || (a.x==b.x && a.y<b.y);
}
ll  Cross(Vector A, Vector B){ return A.x*B.y - A.y*B.x; }

bool used[N];
int mi[N];
void ConvexHull(Point* p, int n, Point* ch)
{
    sort(p, p+n);
    int m = 0;
    for(int i=0; i<n; ++i) {  //缁存姢涓婂嚫鍖?        if(i>1 && p[i].x==p[i-1].x && p[i].y==p[i-1].y) continue;
        while(m>1 && Cross(ch[m-1]-ch[m-2], p[i]-ch[m-2])>0) --m;
        ch[m++] = p[i];
    }
    mes(used, false);
    used[0] = used[m-1] = true;
    for(int i=1; i<m; ++i) {
        if(Cross(ch[i]-ch[i-1], ch[i+1]-ch[i-1]) != 0)
            used[i] = true;
    }
    for(int i=m; i>=0; --i) {
        if(used[i]) mi[i] = ch[i].id;
        else  mi[i] = min(mi[i+1], ch[i].id);
    }
    for(int i=0; i<m; ++i)
        if(mi[i] == ch[i].id)
            printf("%d%c", ch[i].id, " 
"[i==m-1]);
}
Point p[N];
Point vertex[N];
int main()
{
    int T;  scanf("%d", &T);
    while(T--)
    {
        int n;  scanf("%d", &n);
        rep(i,1,n) scanf("%lld%lld", &p[i].x, &p[i].y), p[i].id=i;
        ConvexHull(p+1, n, vertex);
    }

    return 0;
}

以上是关于2018 Multi-University Training Contest 3 1007 / hdu6325 Problem G. Interstellar Travel 鍑稿寘的主要内容,如果未能解决你的问题,请参考以下文章

2018 Multi-University Training Contest 2

2018 Multi-University Training Contest 9

2018 Multi-University Training Contest 4

2018 Multi-University Training Contest 4

2018 Multi-University Training Contest 3

2018 Multi-University Training Contest 8