Pagini recente » Cod sursa (job #273969) | Cod sursa (job #1823318) | Cod sursa (job #851908) | Cod sursa (job #831185) | Cod sursa (job #2756516)
//#include <fstream>
//#include <algorithm>
//#include <cmath>
//using namespace std;
//ifstream in("infasuratoare.in");
//ofstream out("infasuratoare.out");
//const int nmax=120;
//const double eps=1.0e-14;
//struct point
//{
// double x,y;
//}p[nmax],ll;
//int h[nmax];
//double cp(const point &p1,const point &p2,const point &p3)
//{
// return(p2.x-p1.x)*(p3.y-p2.y)-(p2.y-p1.y)*(p3.x-p2.x);
//}
//int ccw(const point &p1,const point &p2,const point &p3)
//{
// double crossp=cp(p1,p2,p3);
// if(fabs(crossp)<eps)
// return 0;
// if(crossp>=eps)
// return 1;
// return -1;
//}
////bool cmp(point &p1,point &p2)
////{
//// return (ccw(ll,p1,p2)>0);
////}
//bool cmp(point &p1,point &p2)
//{
// return ccw(ll,p1,p2)>0;
//}
//double arie_poligon(int n)
//{
// double aria=0;
// int i;
// p[n]=p[0];
// for(i=0;i<n;i++)
// aria+=p[i].x*p[i+1].y-p[i+1].x*p[i].y;
// aria=fabs(aria)*0.5;
// return aria;
//}
//int main()
//{
// int n,i,top;
// double a,b;
// in>>n>>a>>b;
// p[0].x=a;
// p[0].y=b;
// for(i=1;i<n;i++)
// {
// in>>p[i].x>>p[i].y;
// if(p[i].y-p[0].y<=-eps || (fabs(p[i].y-p[0].y)<eps && p[i].x-p[0].x<=-eps))
// swap(p[0],p[i]);
// }
// sort(p+1,p+n,cmp);
// for(i=0;i<n;i++)
// out<<p[i].x<<" "<<p[i].y<<"\n";
// ll=p[0];
// p[n]=p[0];
// h[0]=0;
// h[1]=1;
// top=1;
// i=2;
// while(i<=n)
// {
// if(ccw(p[h[top-1]],p[h[top]],p[i])>0)
// h[++top]=i++;
// else
// top--;
// }
// out<<top<<"\n";
// for(i=0;i<top;i++)
// out<<p[h[i]].x<<" "<<p[h[i]].y<<"\n";
// return 0;
//}
#include <fstream>
#include <algorithm>
#include <math.h>
#include <iomanip>
using namespace std;
ifstream fin("infasuratoare.in");
ofstream fout("infasuratoare.out");
struct Point
{
double x,y;
};
const int NMAX=120000;
const double eps=1.0e-14;
Point P[NMAX+5],LL;
int h[NMAX+5];
double cp(const Point &P1,const Point &P2,const Point &P3)///aria paralelogramului
{
return(P2.x-P1.x)*(P3.y-P2.y)-(P2.y-P1.y)*(P3.x-P2.x);
}
int ccw(const Point &P1,const Point &P2,const Point &P3)///sensul vectorial
{
double crossp=cp(P1,P2,P3);
if(fabs(crossp)<eps)return 0;
if(crossp>-eps)
return 1;
return -1;
}
bool cmp(Point &P1,Point &P2)
{
return ccw(LL,P1,P2)>0;
}
double arie_poligon(int n)
{
double aria;int i;
P[n]=P[0];
aria=0;
for(i=0;i<n;i++)
aria=P[i].x*P[i+1].y-P[i+1].x*P[i].y;
aria=0.5*fabs(aria);
}
int main()
{
int n,i,top;
double a,b;
fin>>n>>a>>b;
P[0].x=a;
P[0].y=b;
for(i=1;i<n;i++)
{
fin>>a>>b;
P[i].x=a;
P[i].y=b;
if(P[i].y-P[0].y<=-eps || (fabs(P[i].y-P[0].y)<eps && P[i].x-P[0].x<=-eps))
swap(P[0],P[i]);
}
LL=P[0];
sort(P+1,P+n,cmp);
for(i=0;i<n;i++)
fout<<P[i].x<<" "<<P[i].y<<"\n";
P[n]=P[0];h[0]=0;h[1]=1;
top=1;i=2;
while(i<=n)
{
if(ccw(P[h[top-1]],P[h[top]],P[i])>0)
h[++top]=i++;
else
--top;
}
fout<<top<<"\n";
for(i=0;i<top;i++)
fout<<fixed<<setprecision(6)<<P[h[i]].x<<" "<<P[h[i]].y<<"\n";
return 0;
}