Pagini recente » Cod sursa (job #1280204) | Cod sursa (job #2774146) | Cod sursa (job #1442122) | Cod sursa (job #948803) | Cod sursa (job #2555630)
#include<bits/stdc++.h>
using namespace std;
ifstream fin("infasuratoare.in");
ofstream fout("infasuratoare.out");
#define x first
#define y second
#define NMAX 120005
typedef pair<double,double > Point;
Point v[NMAX];
Point s[NMAX];
int n;
int head;
void citire()
{
fin>>n;
for(int i=1;i<=n;i++)
{
fin>>v[i].x>>v[i].y;
}
}
inline double cross_product (const Point& a,const Point& b,const Point& c)
{
return (b.x - a.x)*(c.y-a.y) - (b.y-a.y) * (c.x - a.x);
}
inline int cmp(const Point& p1,const Point& p2)
{
return (cross_product(v[1],p1,p2) < 0) ;
}
void sorteaza()
{
int poz=1;
for(int i=2;i<=n;i++)
if(v[i] < v[poz])
poz = i;
swap(v[1],v[poz]);
sort(v+2,v+n+1,cmp);
}
void infasuratoare()
{
sorteaza();
s[1] = v[1];
s[2] = v[2];
head = 2;
for (int i = 3; i <= n; ++i) {
while (head >= 2 && cross_product(s[head - 1], s[head], v[i]) > 0)
--head;
s[++head] = v[i];
}
}
void afisare() {
fout << fixed;
fout << head << "\n";
for (int i = head; i >= 1; --i)
fout << setprecision(9) << s[i].x << " " << s[i].y << "\n";
}
int main()
{
citire();
infasuratoare();
afisare();
return 0;
}