Cod sursa(job #937378)

Utilizator stefan.friptuPetru Stefan Friptu stefan.friptu Data 10 aprilie 2013 10:40:42
Problema Infasuratoare convexa Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.05 kb
#include <cstdio>
#include <algorithm>

using namespace std;
 
int st[120005],head;
struct POINT {
    double x,y;
};

POINT v[120005];
int n;
 
inline void push(int x) {
    st[++head] = x;
}
 
inline double panta(POINT a, POINT b, POINT c) {
    return ((b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x));
}
 
bool cmp(POINT a, POINT b) {
    return (panta(v[1],a,b) < 0);
}
 
int main() {
	
    freopen("infasuratoare.in","r",stdin);
    freopen("infasuratoare.out","w",stdout);
	
    scanf("%d",&n);
    for (int i=1;i<=n;i++) {
        scanf("%lf %lf",&v[i].x,&v[i].y);
        if (v[i].x <= v[1].x) {
            if (v[i].x < v[1].x) swap(v[1],v[i]);
            else if (v[i].y < v[1].y) swap(v[1],v[i]);
        }
    }
	sort(v+2,v+n+1,cmp);
	
    push(1);
    push(2);
	
    for(int i=3;i<=n;i++){
		
        while(panta(v[st[head-1]],v[st[head]],v[i])>0)
			head--;
        push(i);
    }
	
    printf("%d\n",head);
    for (int i=head;i>=1;i--){
        printf("%lf %lf\n",v[st[i]].x,v[st[i]].y);
    }
    return 0;
}