Pagini recente » Cod sursa (job #906483) | Cod sursa (job #2807499) | Cod sursa (job #1141455) | Cod sursa (job #696468) | Cod sursa (job #3353282)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("infasuratoare.in");
ofstream fout("infasuratoare.out");
struct punct
{
double x, y;
};
int n;
vector<punct> a;
void citire_punct(punct &a)
{
fin >> a.x >> a.y;
}
void afis_punct(punct a)
{
fout << a.x << " " << a.y;
}
bool cmp(punct x, punct y)
{
return x.x < y.x;
}
double determinant(punct a, punct b, punct c)
{
return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
}
int main()
{
fin >> n;
for(int i = 1; i <= n; i++)
{
punct x;
citire_punct(x);
a.push_back(x);
}
sort(a.begin(), a.end(), cmp);
vector<punct> stack(n + 2);
int top = 0;
stack[top++] = a[0];
stack[top++] = a[1];
for(int i = 2; i < n; i++)
{
while(top >= 2 and determinant(stack[top - 2], stack[top - 1], a[i]) <= 0)
{
top--;
}
stack[top++] = a[i];
}
// for(int i = 0; i < top; i++)
// {
// afis_punct(stack[i]);
// cout << "\n";
// }
// cout << "\n";
for(int i = n - 1; i >= 0; i--)
{
while(top >= 2 and determinant(stack[top - 2], stack[top - 1], a[i]) <= 0)
top--;
stack[top++] = a[i];
}
fout << top << "\n";
for(int i = 0; i < top - 1; i++)
{
afis_punct(stack[i]);
fout << "\n";
}
return 0;
}