Pagini recente »
Istoria paginii runda/vaslui_cls78_02.02
|
Istoria paginii runda/2014-01-19-test-78
|
Istoria paginii runda/probleme_istet
|
Cod sursă (job #731458)
|
Cod sursă (job #490256)
Cod sursă (job
#490256)
#include <bits/stdc++.h>
using namespace std;
ifstream in("infasuratoare.in");
ofstream out("infasuratoare.out");
const int NMAX = 120000;
struct punct {
int x, y;
};
int N, nrP;
punct P[NMAX+1], st[NMAX+1];
long long dist2(const punct& A, const punct& B) {
long long dX = A.x - B.x,
dY = A.y - B.y;
return dX * dX + dY * dY;
}
long long det(const punct& A, const punct& B, const punct& C) {
return 1LL * (A.x - B.x) * (A.y - C.y) - 1LL * (A.y - B.y) * (A.x - C.x);
}
bool compd(const punct& A, const punct& B) {
long long dd = det(P[1], A, B);
if(dd == 0)
return dist2(P[1], A) < dist2(P[1], B);
return dd > 0;
}
bool compy(const punct& A, const punct& B) {
if(A.y == B.y) return A.x < B.x;
return A.y < B.y;
}
void graham() {
sort(P+2, P+N+1, compd);
st[1] = P[1];
st[2] = P[2];
nrP = 2;
P[N+1] = P[1];
for(int i = 3; i <= N + 1; i++) {
while(nrP >= 2 && det(st[nrP-1], st[nrP], P[i]) <= 0)
nrP--;
st[++nrP] = P[i];
}
nrP--;
}
void show() {
out << nrP << '\n';
for(int i = 1; i <= nrP; i++)
out << st[i].x << ' ' << st[i].y << '\n';
}
int main()
{
in >> N;
int pMin = 1;
for(int i = 1; i <= N; i++) {
in >> P[i].x >> P[i].y;
if(compy(P[i], P[pMin]))
pMin = i;
}
swap(P[1], P[pMin]);
graham();
show();
return 0;
}