Pagini recente » Cod sursa (job #2345937) | Cod sursa (job #1818906) | Cod sursa (job #1582780) | Cod sursa (job #2950133) | Cod sursa (job #1142900)
#include<fstream>
#include<algorithm>
#include<vector>
#include<stack>
#include<iomanip>
#define Nmax 120010
#define x first
#define y second
using namespace std;
typedef pair<double, double> Point;
ifstream fin("infasuratoare.in");
ofstream fout("infasuratoare.out");
Point S[Nmax], V[Nmax];
int top,N ;
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);
}
bool cmp(const Point &a, const Point &b)
{
return cross_product(V[1], a, b)<0;
}
void Sort()
{
int pos = 1, i;
for (i=2; i <=N;++i)
if (V[i] < V[pos])
pos = i;
swap(V[1], V[pos]);
sort(V + 2, V+N+1, cmp);
}
void ConvexHull()
{
Sort();
top = 0;
S[++top] = V[1];
S[++top] = V[2];
for (int i = 3; i <=N; ++i)
{
while (cross_product(S[top-1], S[top], V[i])>0 && top >= 2)
--top;
S[++top] = V[i];
}
}
int main()
{
double a, b;
fin >> N;
for (int i = 1; i <= N; ++i)
{
fin >> a >> b;
Point p = make_pair(a, b);
V[i] = p;
}
ConvexHull();
fout << fixed;
fout << top << '\n';
for (int i = top; i >= 1; --i)
fout << setprecision(12)<<S[i].x << ' ' << S[i].y << '\n';
return 0;
}