Pagini recente »
Istoria paginii utilizator/andreitse
|
Cod sursă (job #15015)
|
Cod sursă (job #683607)
|
Borderou de evaluare (job #587029)
|
Cod sursă (job #307187)
Cod sursă (job
#307187)
#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';
g << st[1].x << ' ' << st[1].y << '\n';
for(int i = H; i > 1; 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];
double dd;
for(int i = 3; i <= N+1; i++)
{
while(H >= 2 && (dd=det(st[H - 1], st[H], p[i])) > 0)
H--;
st[++H] = p[i];
}
H--;
afis();
return 0;
}