Pagini recente » Cod sursa (job #675036) | Cod sursa (job #1663331) | Cod sursa (job #1543164) | Cod sursa (job #1046119) | Cod sursa (job #2878544)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("infasuratoare.in");
ofstream fout("infasuratoare.out");
struct pct
{
double first,second;
} a[120005];
double det(pct z,pct x, pct y)
{
return(z.first*x.second+x.first*y.second+y.first*z.second-x.second*y.first-y.second*z.first-z.second*x.first);
}
bool comp(pct x,pct y)
{
return det(a[1],x,y)>0;
}
int main()
{
int n;
int i;
int mn;
fin>>n;
fin>>a[1].first>>a[1].second;
mn=1;
for(i=2; i<=n; i++)
{
fin>>a[i].first>>a[i].second;
if(a[i].first<a[mn].first||(a[i].first==a[mn].first&&a[i].second<a[mn].second))mn=i;
}
swap(a[mn],a[1]);
sort(a+2,a+n+1,comp);
a[n+1]=a[1];
n++;
int l=2;
for(i=3; i<=n; i++)
{
while(l>=2&&det(a[l-1],a[l],a[i])<0)l--;
a[++l]=a[i];
}
fout<<l-1<<'\n';
for(i=1; i<l; i++)
{
fout<<fixed<<setprecision(12)<<a[i].first<<" "<<a[i].second<<'\n';
}
return 0;
}