Pagini recente » Cod sursa (job #2105734) | Cod sursa (job #1958572) | Cod sursa (job #679262) | Cod sursa (job #2444634) | Cod sursa (job #3213785)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("infasuratoare.in");
ofstream fout("infasuratoare.out");
pair<double,double> a[120003];
int n;
bool viz[120005];
int st[120005], top;
double F(pair<double,double> A, pair<double,double> B, pair<double,double>C)
{
return (A.second - B.second) * C.first + (B.first - A.first) * C.second
+ A.first * B.second - A.second * B.first;
}
int main()
{
fin >> n;
int i;
for (i = 1; i <= n; i++)
fin >> a[i].second>> a[i].first ;
sort(a + 1, a + n + 1);
for (i = 1; i <= n; i++)
swap(a[i].first,a[i].second);
st[++top] = 1;
st[++top] = 2;
viz[2] = 1;
for (i = 3; i <= n; i++)
{
while (top >= 2 and F(a[st[top - 1]], a[st[top]], a[i]) <= 0)
{
viz[st[top]] = 0;
top--;
}
st[++top] = i;
viz[i] = 1;
}
for (i = n; i >= 1; i--)
{
if (viz[i] == 0)
{
while (top >= 2 and F(a[st[top - 1]], a[st[top]], a[i]) <= 0)
top--;
st[++top] = i;
}
}
fout << top - 1 << "\n";
for (int i = 1; i < top; i++)
fout << setprecision(12) << fixed << a[st[i]].first << " " << a[st[i]].second << "\n";
return 0;
}