Pagini recente » Profil gudeialina | Cod sursa (job #2476198) | Cod sursa (job #2907721) | Cod sursa (job #445643) | Cod sursa (job #1362215)
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;
#ifdef HOME
const string inputFile = "input.txt";
const string outputFile = "output.txt";
#else
const string problemName = "infasuratoare";
const string inputFile = problemName + ".in";
const string outputFile = problemName + ".out";
#endif
typedef pair<double, double> PDD;
const int NMAX = 120000 + 5;
int N, M;
PDD P[NMAX];
PDD H[NMAX];
double cp(PDD A, PDD B, PDD C) {
return (A.first - C.first) * (B.second - C.second) - (A.second - C.second) * (B.first - C.first);
}
struct cmp {
bool operator()(PDD A, PDD B) {
return cp(A, B, P[1]) > 0;
}
};
int main() {
int i;
freopen(inputFile.c_str(), "r", stdin);
freopen(outputFile.c_str(), "w", stdout);
scanf("%d", &N);
for(i = 1; i <= N; i++) {
scanf("%lf%lf", &P[i].first, &P[i].second);
if(P[i] < P[1])
swap(P[1], P[i]);
}
sort(P + 2, P + N + 1, cmp());
for(i = 1; i <= N; i++) {
while(M > 2 && cp(H[M - 1], H[M], P[i]) < 0)
M--;
H[++M] = P[i];
}
printf("%d\n", M);
for(i = 1; i <= M; i++)
printf("%.12f %.12f\n", H[i].first, H[i].second);
return 0;
}