Pagini recente » Cod sursa (job #657619) | Cod sursa (job #1804653) | Cod sursa (job #2179929) | Cod sursa (job #882824) | Cod sursa (job #2149400)
#include <fstream>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;
struct vct
{
double x,y;
}v[120000];
struct stiva
{
double x,y,z;
}t1[80000],t2[80000];
bool cmp (vct A ,vct B)
{
if(A.y==B.y)
return A.x>B.x;
else
return A.y<B.y;
}
double tg(double b , double a)
{
a=a-v[1].y;
b=abs(b-v[1].x);
if(a==0)
return 1000;
else
return b/a;
}
double c;
int i,n,k=1,p=1;
int main()
{
ifstream f("infasuratoare.in");
ofstream g("infasuratoare.out");
f>>n;
for(i=1;i<=n;i=i+1)
{
f>>v[i].x;
f>>v[i].y;
}
sort(v+1,v+1+n,cmp);
t1[1].x=v[1].x ; t1[1].y=v[1].y ;
t2[1].x=v[1].x ; t2[1].y=v[1].y ;
for(i=2;i<=n;i=i+1)
{
if(v[i].x>=v[1].x)
{
if(v[i].x<t1[k].x)
{
t1[++k].x=v[i].x;
t1[k].y=v[i].y;
t1[k].z=tg(v[i].x,v[i].y);
}
else
{
c=tg(v[i].x,v[i].y);
while(c>t1[k].z && k>1)
k--;
t1[++k].x=v[i].x;
t1[k].y=v[i].y;
t1[k].z=c;
}
}
else
{
if(v[i].x>t2[p].x)
{
t2[++p].x=v[i].x;
t2[p].y=v[i].y;
t2[p].z=tg(v[i].x,v[i].y);
}
else
{
c=tg(v[i].x,v[i].y);
while(c>t2[p].z && p>1)
p--;
t2[++p].x=v[i].x;
t2[p].y=v[i].y;
t2[p].z=c;
}
}
}
for(i=1;i<=k;i=i+1)
g<<fixed<<setprecision(6)<<t1[i].x<<' '<<fixed<<setprecision(6)<<t1[i].y<<'\n';
for(i=p;i>=2;i--)
g<<fixed<<setprecision(6)<<t2[i].x<<' '<<fixed<<setprecision(6)<<t2[i].y<<'\n';
g<<sizeof(double);
return 0;
}