POJ 1696 (convex hull deformation)

Title: Portal

Meaning of the questions: n points to you, then, there was an ant, ants can only ask you turn left and go straight, and asked how to get to the ants to walk up to a point.

 

Solution: in fact, is seeking a number of convex hull, the ant can certainly go through all the points.

 

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <queue>
#include <map>
#include <vector>
#include <set>
#include <string>
#include <math.h>
#define LL long long
#define mem(i, j) memset(i, j, sizeof(i))
#define rep(i, j, k) for(int i = j; i <= k; i++)
#define dep(i, j, k) for(int i = k; i >= j; i--)
#define pb push_back
#definethe make_pair the make
 #define INF INT_MAX
 #define INF LLONG_MAX
 #define the PI ACOS (-1)
 the using  namespace STD; 

const  int N = 5E4 + . 5 ; 

struct Point {
     int ID;
     Double X, Y; 
    Point ( Double X = 0 , Double Y = 0 ): X (X), Y (Y) {} /// constructor 
}; 

typedef point the vector; 
/// vector + vector = vector + vector = vector point 
the vector operator + (the vector A, the vector B) { returnThe Vector (Ax of + Bx, Ay + By);}
 /// point - point = vector of 
the Vector operator - (Point A, Point B) { return the Vector (Ax of - Bx, Ay - By);}
 /// vector * Number = vector of 
the vector operator * (the vector A, Double P) { return the vector (Ax of P *, Ay * P);}
 /// vector / vector number = 
the vector operator / (the vector A, Double P) { return the vector (Ax of / P, Ay / P);} 

const  Double EPS = 1E- 10 ;
 int dCMP ( Double X) {
    if(fabs(x) < eps) return 0; else return x < 0 ? -1 : 1;
}

bool operator < (const Point& a, const Point& b) {
    return a.x == b.x ? a.y < b.y : a.x < b.x;
}

bool operator == (const Point& a, const Point &b) {
    return dcmp(a.x - b.x) == 0 && dcmp(a.y - b.y) == 0;
}

doubleDOT (the Vector A, the Vector B) { return Ax of Ay * Bx + By *;} /// dot product 
double the Length (the Vector A) { return sqrt (DOT (A, A));} /// calculated vector length 
double angle (the vector A, the vector B) { return ACOS (Dot (A, B) / the Length (A) / the Length (B));} /// vector A, B angle 
Double Cross (the vector A, the vector B) { return Ax of * By - Ay * Bx;} /// cross product of 


Point P [N], ANS [N]; 
BOOL VIS [N];
 void , ConvexHull ( int ST, int n-) { 
    MEM (VIS, 0 );
     int k = 0, t = 1;
    while(k < n) {
        rep(i, st, n - 1) {
            if(vis[P[i].id]) continue;
            while(k > t && Cross(ans[k - 1] - ans[k - 2], P[i] - ans[k - 1]) <= 0) k--, vis[ans[k].id] = 0;
            ans[k++] = P[i]; vis[P[i].id] = 1;
        }
        t = k;
        dep(i, 0, n - 2) {
            if(vis[P[i].id]) continue;
            while(k > t && Cross(ans[k - 1] - ans[k - 2], P[i] - ans[k - 1]) <= 0) k--, vis[ans[k].id] = 0;
            ans[k++] = P[i]; vis[P[i].id] = 1;
        }
        t = k; st = 0;
    }
}

void solve() {
    int n;
    scanf("%d", &n);
    double mi = 150.0, pos = -1;
    rep(i, 0, n - 1) {
        scanf("%d %lf %lf", &P[i].id, &P[i].x, &P[i].y);
    }
    sort(P, P + n);
    rep(i, 0, n - 1) if(P[i].y < mi) mi = P[i].y, pos = i;
    ConvexHull(pos, n);
    printf("%d ", n);
    rep(i, 0, n - 1) printf("%d ", ans[i].id); puts("");
}

int main() {
    int _; scanf("%d", &_);
    while(_--) solve();
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/Willems/p/12346573.html
Recommended