Pagini recente » Cod sursa (job #3204469) | Cod sursa (job #2831040) | Cod sursa (job #2110882) | Cod sursa (job #1786851) | Cod sursa (job #3284714)
#include <vector>
#include <fstream>
#include <bitset>
#include <algorithm>
#include <iomanip>
#include <iostream>
using namespace std;
ifstream fin("infasuratoare.in");
ofstream fout("infasuratoare.out");
int n;
struct da {
double x, y;
bool operator < (const da& other)const
{
if (this->y == other.y)
return this->x < other.x;
return this->y < other.y;
}
};
da a[120004];
int st[120004];
bitset<120005> fr;
bool isleft(da a, da b, da c)
{
return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x) > 0;
}
int main()
{
fin >> n;
for (int i = 1; i <= n; i++)
fin >> a[i].x >> a[i].y;
sort(a + 1, a + n + 1);
st[1] = 1;
st[2] = 2;
fr[1] = 1;
fr[2] = 1;
int top = 2;
cout << "DA";
for (int i = 3; i <= n; i++)
{
while (top >= 2 && !isleft(a[st[top - 1]], a[st[top]], a[i]))
{
fr[st[top]] = 0;
top--;
}
st[++top] = i;
fr[i] = 1;
}
fr[1] = 0;
for (int i = n; i >= 1; i--)
{
if (!fr[i])
{
while (top >= 2 && !isleft(a[st[top - 1]], a[st[top]], a[i]))
{
fr[st[top]] = 0;
top--;
}
}
fr[i] = 1;
st[++top] = i;
}
fout << top - 1 << "\n";
for (int i = 1; i < top; i++)
fout << fixed << setprecision(6) << a[st[i]].x << " " << a[st[i]].y << "\n";
return 0;
}