Pagini recente » Cod sursa (job #2880546) | Cod sursa (job #1059611) | Cod sursa (job #2976964) | Cod sursa (job #2185300) | Cod sursa (job #1075247)
#include <fstream>
#include <vector>
#include <algorithm>
#define dmax 120000
#define inf 1000000006
using namespace std;
struct point
{
double x,y;
};
vector <point> v(dmax);
vector <point> hull;
point a,b;
int n;
double s;
void read()
{
int poz=0;
scanf("%i",&n);
for(int i=0; i<n; i++)
{
scanf("%lf%lf",&v[i].x,&v[i].y);
if(v[i].x<v[poz].x)
poz=i;
else if(v[i].x==v[poz].x)
if(v[i].y>v[poz].y)
poz=i;
}
swap(v[0],v[poz]);
}
double polar(point x1)
{
point p1;
int x;
p1.x=x1.x-a.x;
p1.y=x1.y-a.y;
if(p1.y<0) x=-1;
else x=1;
return x*p1.y*p1.y/(p1.y*p1.y+p1.x*p1.x);
}
double area(point p1, point p2, point p3)
{
return (p1.x*p2.y+p1.y*p3.x+p2.x*p3.y-p2.x*p1.y-p1.x*p3.y-p3.x*p2.y)/2;
}
bool compare(point p1, point p2)
{
return (polar(p1)>polar(p2));
}
void write()
{
printf("%i%c",hull.size(),'\n');
printf("%.12f%c%.12f%c",hull[0].x,' ',hull[0].y,'\n');
for(int i=hull.size()-1; i>0; i--)
printf("%.12f%c%.12f%c",hull[i].x,' ',hull[i].y,'\n');
}
int main()
{
freopen("infasuratoare.in","r",stdin);
freopen("infasuratoare.out","w",stdout);
read();
a=v[0];
sort(v.begin()+1, v.begin()+n, compare);
hull.push_back(a);
hull.push_back(v[1]);
for(int i=2; i<n; i++)
{
while(area(hull[hull.size()-2],hull[hull.size()-1],v[i])>0 && hull.size()>2)
hull.pop_back();
hull.push_back(v[i]);
}
write();
return 0;
}