Mai intai trebuie sa te autentifici.
Cod sursa(job #1453196)
Utilizator | Data | 22 iunie 2015 22:19:38 | |
---|---|---|---|
Problema | Infasuratoare convexa | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 1.97 kb |
#define REP(a,b) for(int a=0; a<(b); ++a)
#define FWD(a,b,c) for(int a=(b); a<(c); ++a)
#define FWDS(a,b,c,d) for(int a=(b); a<(c); a+=d)
#define BCK(a,b,c) for(int a=(b); a>(c); --a)
#define ALL(a) (a).begin(), (a).end()
#define SIZE(a) ((int)(a).size())
#define VAR(x) #x ": " << x << " "
#define FILL(x,y) memset(x,y,sizeof(x))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define MAX(a,b) (((a)>(b))?(a):(b))
#define x first
#define y second
#define st first
#define nd second
#define pb push_back
#define l(n) (n<<1)
#define r(n) ((n<<1)+1)
#define f(n) (n>>1)
#define lsb(a) (a&-a)
#include<vector>
#include<algorithm>
#include<iomanip>
using namespace std;
#include<fstream>
ifstream cin("infasuratoare.in");
ofstream cout("infasuratoare.out");
const int NMAX = 120010;
const int INF = 0x3f3f3f3f;
const int dx[] = {0,0,-1,1}; //1,1,-1,1};
const int dy[] = {-1,1,0,0}; //1,-1,1,-1};
typedef long long LL;
typedef pair<int, int> PII;
typedef long double K;
typedef pair<K, K> PKK;
typedef vector<int> VI;
int n,m,k,t;
struct Point
{
double x,y;
};
bool cmp(Point l, Point r)
{
return (l.x<r.x || (l.x==r.x && l.y<r.y));
}
double orientation(Point a, Point b, Point c)
{
/*
orientation < 0 then counter-clockwise
orientation = 0 then collinear
orientation > 0 then clockwise
*/
return (b.y-a.y)*(c.x-b.x)-(b.x-a.x)*(c.y-b.y);
}
Point P[NMAX];
Point H[NMAX<<1];
int main()
{
ios_base::sync_with_stdio(true);
cout<<setprecision(6)<<fixed;
cin>>n;
REP(i,n)
cin>>P[i].x>>P[i].y;
sort(P, P+n, cmp);
int i;
for(i=0, k=0; i<n; ++i)
{
while(k>=2 && orientation(H[k-2], H[k-1], P[i])<=0)
k--;
H[k++]=P[i];
}
for(i=n-2, t=k+1; i>=0; --i)
{
while(k>=t && orientation(H[k-2], H[k-1], P[i])<=0)
k--;
H[k++]=P[i];
}
/*
H[i] hull of size k
*/
cout<<--k<<" \n";
BCK(i,k-1,-1)
cout<<1.00*H[i].x<<" "<<1.00*H[i].y<<"\n";
return 0;
}