Cod sursa(job #886766)

Utilizator DanutsDanut Rusu Danuts Data 23 februarie 2013 11:27:35
Problema Infasuratoare convexa Scor 50
Compilator cpp Status done
Runda Arhiva educationala Marime 0.96 kb
#include<stdio.h>
#include<algorithm>

using namespace std;

#define esp 1e-12
#define max_n 120001

struct punct{double x,y;};

punct v[max_n];
int ok[max_n],s[max_n];

int n,h;

int compar(punct a,punct b){
	return (a.x<b.x) || (a.x==b.x && a.y<b.y);
}
int semn(punct o,punct a,punct b){
	return (a.x-o.x)*(b.y-o.y) - (b.x-o.x)*(a.y-o.y);
}
void convex(){
	sort(v+1,v+n+1,compar);
	int k=2,q=1,i=3;
	s[1]=1;s[2]=2;
	ok[2]=1;
	while(!ok[1]){
		while(ok[i]){
			if(i==n) q=-1;
			i+=q;
		}
		while(k>=2 && semn(v[s[k-1]],v[s[k]],v[i])<esp)
			ok[s[k--]]=0;
		s[++k]=i;
		ok[i]=1;
	}
	h=k-1;
}
void citire(){
	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);
}
void afis(){
	printf("%d\n",h);
	for(int i=2;i<=h+1;i++)
		printf("%lf %lf\n",v[s[i]].x,v[s[i]].y);
}
int main (){
	citire();
	convex();
	afis();
	return 0;
}