Pagini recente » Cod sursa (job #1623820) | Cod sursa (job #2281587) | Cod sursa (job #817808) | Cod sursa (job #74971) | Cod sursa (job #1757892)
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#define x first
#define y second
using namespace std;
const int nmx = 120002;
int n;
pair <double,double> v[nmx];
vector <pair<double,double> > st;
void citire()
{
scanf("%d", &n);
for(int i = 1; i <= n; ++i)
scanf("%lf %lf", &v[i].first, &v[i].second);
}
void alegere_minim()
{
int pmin = 1;
for(int i = 2; i <= n; ++i)
if(v[i] < v[pmin])
pmin = i;
swap(v[1],v[pmin]);
}
double determinant(pair <double,double> p1, pair <double,double> p2, pair <double,double> p3)
{
return (p2.x-p1.x) * (p3.y - p1.y) - (p2.y - p1.y) * (p3.x - p1.x);
}
struct Cmp
{
bool operator() (pair <double,double> p1, pair <double,double> p2)
{
return determinant(v[1],p1,p2) > 0;
}
} cmp;
void stiva_stuff()
{
for(int i = 1; i <= n; ++i)
{
while(st.size() >= 2 && determinant(st[st.size()-2],st[st.size()-1],v[i]) < 0)
st.pop_back();
st.push_back(v[i]);
}
}
void afish()
{
printf("%d\n", st.size());
for(vector<pair<double,double> >::iterator it = st.begin(); it != st.end(); ++it)
printf("%.6f %.6f\n", it->first, it->second);
}
int main()
{
freopen("infasuratoare.in", "r", stdin);
freopen("infasuratoare.out", "w", stdout);
citire();
alegere_minim();
sort(v + 2, v + n + 1, cmp);
stiva_stuff();
afish();
return 0;
}