Pagini recente » Cod sursa (job #2076060) | Cod sursa (job #1174238) | Cod sursa (job #1145095) | Cod sursa (job #2569990) | Cod sursa (job #2390691)
#include <bits/stdc++.h>
#define NMAX 120005
using namespace std;
ifstream fin("infasuratoare.in");
ofstream fout("infasuratoare.out");
int n,vf,max1;
struct punct{
double x,y;
}v[NMAX],st[NMAX],sol[NMAX];
bool cmp(punct a,punct b){
if(a.x < b.x) return true;
if(a.x == a.y) return a.y < b.y;
}
void Citire_sortare(){
fin>>n;
for(int i=1;i<=n;i++){
fin>>v[i].x>>v[i].y;
}
sort(v+1,v+n+1,cmp);
}
int det(punct a,punct b,punct c){
return a.x*b.y+b.x*c.y+c.x*a.y-b.y*c.x-c.y*a.x-a.y*b.x;
}
int main()
{
int i;
Citire_sortare();
st[++vf]=v[1];
for(i=2;i<=n;i++){
while(vf>1 && det(st[vf-1],st[vf],v[i])<0)
vf--;
st[vf++]=v[i];
}
for(i=1;i<=vf;i++){
sol[i]=st[i];
}
max1=vf;
vf=0;
st[++vf]=v[n];
for(i=n-1;i>=1;i--){
while(vf>1&&det(st[vf-1],st[vf],v[i]))
vf--;
st[++vf]=v[i];
}
for(i=1;i<=vf;i++){
sol[i+max1]=st[i];
}
max1=max1+vf;
fout<<max1<<"\n";
fout<<fixed<<setprecision(6);
for(i=1;i<=max1;i++){
fout<<sol[i].x<<" "<<sol[i].y<<"\n";
}
return 0;
}