Pagini recente » Cod sursa (job #38342) | Cod sursa (job #548697) | Cod sursa (job #1690307) | Cod sursa (job #2682426) | Cod sursa (job #1598314)
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
const double eps = 1.e-14;
int h[120010];
struct POINT{
double x,y;
};
POINT LL;
vector<POINT> points;
bool cmp(POINT a, POINT b){
if(fabs(a.y - b.y) <= eps)
return a.x - b.x <= -eps;
return a.y - b.y <= -eps;
}
int ccw(POINT a, POINT b, POINT c){
double cp;
cp = (b.x - a.x)*(c.y - b.y) - (b.y - a.y)*(c.x - b.x);
if(fabs(cp) <= eps)
return 0;
if(cp >= eps)
return 1;
return -1;
}
bool My_sort(POINT a, POINT b){
return ccw(LL, a, b) > 0;
}
int main()
{
int i,n, top;
double x,y;
freopen("infasuratoare.in","r",stdin);
freopen("infasuratoare.out","w",stdout);
scanf("%d", &n);
for(i=1; i<=n; ++i){
scanf("%lf%lf", &x, &y);
points.push_back({x*1.0, y*1.0});
}
sort(points.begin(), points.end(), cmp);
LL = points[0];
sort(points.begin()+1, points.end(), My_sort);
points.push_back(points[0]);
h[0] = 0;
h[1] = 1;
top = 1;
i = 2;
while(i <= n){
if(ccw(points[h[top-1]], points[h[top]], points[i]) > 0){
h[++top] = i;
++i;
}
else
--top;
}
printf("%d\n",top);
for(i=0; i<top; ++i)
printf("%.6lf %.6lf\n", points[h[i]].x, points[h[i]].y);
return 0;
}