Pagini recente » Cod sursa (job #1538114) | Cod sursa (job #2703015) | Cod sursa (job #2120370) | Cod sursa (job #1086257) | Cod sursa (job #2964738)
#include <fstream>
#include <algorithm>
#define x first
#define y second
using namespace std;
ifstream fin("infasuratoare.in");
ofstream fout("infasuratoare.out");
typedef pair<double, double> pct;
const int nMax=12e4+5;
int n, poz, top;
pct v[nMax], stiva[nMax];
double semn(const pct& a, const pct& b, const pct& c)
{
return a.x*(b.y-c.y)+b.x*(c.y-a.y)+c.x*(a.y-b.y);
}
bool cmp(const pct& a, const pct& b)
{
return semn(v[1], a, b) > 0;
}
int main()
{
ios_base::sync_with_stdio(false);
fin.tie(0);
fin>>n;
v[0].x=v[0].y=1e9+100, poz=0;
for(int i=1; i<=n; i++)
{
fin>>v[i].x>>v[i].y;
if(v[i].x < v[poz].x || (v[i].x==v[poz].x && v[i].y < v[poz].y))
poz=i;
}
swap(v[1], v[poz]);
sort(v+2, v+n+1, cmp);
stiva[1]=v[1], stiva[2]=v[2];
top=2;
for(int i=3; i<=n; i++)
{
while(top>1 && semn(stiva[top-1], stiva[top], v[i])<0)
top--;
stiva[++top]=v[i];
}
fout<<top<<'\n';
fout.precision(6);
for(int i=1; i<=top; i++)
fout<<fixed<<stiva[i].x<<' '<<stiva[i].y<<'\n';
fin.close();
fout.close();
return 0;
}