Pagini recente » Cod sursa (job #35663) | Cod sursa (job #2254357) | Cod sursa (job #754577) | Cod sursa (job #208923) | Cod sursa (job #2626792)
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
const double eps=1.0e-12;
struct POINT{
double x,y;
};
POINT LL,p[120005];
int h[120005];
int CCW(POINT P1,POINT P2,POINT P3){
double cp;
cp=(1.0*P2.x-P1.x)*(1.0*P3.y-P2.y)-(1.0*P2.y-P1.y)*(1.0*P3.x-P2.x);
if(fabs(cp)<eps){
return 0;
}else if(cp>=eps){
return 1;
}
return -1;
}
bool cmp(POINT P1,POINT P2){
if(CCW(LL,P1,P2)==1){
return 1;
}else{
return 0;
}
}
int main(){
freopen("infasuratoare.in","r",stdin);
freopen("infasuratoare.out","w",stdout);
int n,i,top;
scanf("%d",&n);
scanf("%lf%lf",&p[0].x,&p[0].y);
for(i=1;i<n;++i){
scanf("%lf%lf",&p[i].x,&p[i].y);
if(p[i].y-p[0].y<=-eps || (fabs(p[i].y-p[0].y)<eps && (p[i].x-p[0].x)<=-eps)){
swap(p[0],p[i]);
}
}
LL=p[0];
sort(p+1,p+n,cmp);
top=1;
h[0]=0;
h[1]=1;
i=2;
p[n]=p[0];
while(i<=n){
if(CCW(p[h[top-1]],p[h[top]],p[i])>0){
h[++top]=i;
i++;
}else{
top--;
}
}
printf("%d\n",top);
for(i=0;i<top;++i){
printf("%lf %lf\n",p[h[i]].x,p[h[i]].y);
}
return 0;
}