Pagini recente » Cod sursa (job #2921832) | Cod sursa (job #2198948) | Cod sursa (job #2902080) | Cod sursa (job #1432305) | Cod sursa (job #1648826)
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
#define MAXN 120005
struct pc
{
double x,y;
}act;
vector<pc> v;
int n,i,nrst,mn;
int st[MAXN];
double determinant(pc A, pc B, pc C)
{
return (A.x - B.x)*(B.y - C.y) - (B.x - C.x)*(A.y - B.y);
}
bool cmp(pc A, pc B)
{
return determinant(v[0], A, B) > 0;
}
int main()
{
freopen("infasuratoare.in","r",stdin);
freopen("infasuratoare.out","w",stdout);
scanf("%d",&n);
for(i=1; i<=n; i++)
{
scanf("%lf %lf", &act.x, &act.y);
v.push_back(act);
}
mn=0;
for(i=1; i< v.size(); i++)
if(v[i].x < v[mn].x || ( v[i].x == v[mn].x && v[i].y < v[mn].y))
mn=i;
swap(v[mn],v[0]);
sort(v.begin()+1, v.end(), cmp);
for(i=0; i<v.size(); i++)
{
while(nrst >= 2 && determinant(v[ st[ nrst-1 ] ], v[ st[ nrst ]], v[i]) < 0 )
nrst--;
st[ ++nrst ] = i;
}
printf("%d\n",nrst);
for(i=1; i<=nrst; i++)
printf("%lf %lf\n", v[ st[i] ].x, v[ st[i] ].y);
return 0;
}