Pagini recente » Cod sursa (job #2985571) | Cod sursa (job #3250965) | Cod sursa (job #2749826) | Cod sursa (job #1461307) | Cod sursa (job #1579570)
//Roberto Deresu - FMI
//Re :)
#include <iostream>
#include <fstream>
#include <climits>
#define nx 120007
using namespace std;
int n;
struct Point
{
double x;
double y;
} *points, first, current, nextp;
ifstream fin("infasuratoare.in");
ofstream fout("infasuratoare.out");
double CrossProduct(Point A, Point B, Point C)
{
return (B.x - A.x) * (C.y - A.y) - (B.y - A.y) * (C.x - A.x);
}
int main()
{
fin >> n;
first.x = first.y = INT_MAX;
points = new Point[n];
for (int index = 0; index < n; index++)
{
fin >> points[index].x >> points[index].y;
if (points[index].x < first.x || (points[index].x == first.x && points[index].y < first.y))
{
first = points[index];
}
}
current = first;
while (first.x != nextp.x || first.y != nextp.y) //first != nextp
{
if (points[0].x == current.x && points[0].y == current.y)
{
nextp = points[1];
}
else
{
nextp = points[0];
}
for (int index = 0; index < n; index++)
{
if (CrossProduct(current, nextp, points[index]) < 0)
{
nextp = points[index];
}
}
fout << nextp.x << " " << nextp.y << "\n";
current = nextp;
}
return 0;
}