Pagini recente »
Cod sursă (job #357163)
|
Cod sursă (job #443424)
|
Cod sursă (job #819696)
|
Cod sursă (job #344367)
|
Cod sursă (job #307183)
Cod sursă (job
#307183)
#include <iostream>
#include <fstream>
#include <iomanip>
#include <algorithm>
using namespace std;
ifstream f("infasuratoare.in");
ofstream g("infasuratoare.out");
struct punct
{
double x, y;
};
punct p[100002], st[1002];
int N, H;
void afis()
{
g << H << '\n';
for(int i = H; i > 0; i--)
g << st[i].x << ' ' << st[i].y << '\n';
}
void swap(punct &A, punct &B)
{
punct aux;
aux = A;
A = B;
B = aux;
}
int compy(const punct &A, const punct &B)
{
if(A.y == B.y) return A.x < B.x;
return A.y < B.y;
}
double det(const punct &A, const punct &B, const punct &C)
{
return (A.x - B.x) * (A.y - C.y) - (A.y - B.y) * (A.x - C.x);
}
int compd(const punct &A, const punct &B)
{
return det(p[1], A, B) < 0;
}
int main()
{
f >> N;
int ip0 = 1;
for(int i = 1; i <= N; i++)
{
f >> p[i].x >> p[i].y;
if(compy(p[i], p[ip0]))
ip0 = i;
}
swap(p[ip0], p[1]);
sort(p + 2, p + N + 1, compd);
st[1] = p[1];
st[2] = p[2];
H = 2;
p[N+1]=p[1];
for(int i = 3; i <= N+1; i++)
{
while(H >= 2 && det(st[H - 1], st[H], p[i]) >= 0)
H--;
st[++H] = p[i];
}
H--;
afis();
return 0;
}