Pagini recente » Cod sursa (job #2345955) | Cod sursa (job #930807) | Cod sursa (job #1632212) | Cod sursa (job #2704511) | Cod sursa (job #1646334)
#include <fstream>
#include <iostream>
#include <vector>
#include <stack>
#include <utility>//pair
#include <algorithm>
#include <iomanip>
#define Inf (1<<31)-1
using namespace std;
vector<pair<double,double> > v;
vector< pair<pair<double,double>, double> > nv;
pair<double,double> mini;
int N;
double abs(double x) {
return (x<0 ? -x: x);
}
double tg(pair<double,double> a) {
double x,y;
x=(a.first - mini.first);
y=(a.second - mini.second);
if(x==0) {
if (y == 0)
return Inf;
else
return Inf-1;
}
return y/x;
}
int cmp(const pair<double,double> &a, const pair<double,double> &b) {
double tg1, tg2;
tg1 = tg(a);
tg2 = tg(b);
return tg1 > tg2;
}
void citire() {
int i;
double x, y;
scanf("%d", &N);
mini.second = Inf;
mini.first = Inf;
for(i=1; i<=N; i++) {
scanf("%lf %lf", &x, &y);
if(x<mini.first || (x == mini.first && y < mini.second))
mini=make_pair(x,y);
v.push_back(make_pair(x,y));
}
}
bool left_turn (const pair<double, double> &p1, const pair<double, double> &p2, const pair<double, double> &p3) {
return (p2.first - p1.first)*(p3.second - p1.second) - (p3.first - p1.first)*(p2.second - p1.second) > 0;
}
int main() {
freopen("infasuratoare.in","rt",stdin);
freopen("infasuratoare.out","wt",stdout);
citire();
sort(v.begin(),v.end(),cmp);
vector<int> S;
S.push_back(0);
for(int i=1; i<N; i++) {
while(S.size() >= 2 && left_turn(v[ S[S.size()-2] ], v[S.back()], v[i]))
S.pop_back();
S.push_back(i);
}
cout<<S.size()<<'\n';
for(int i=S.size()-1; i>=0; --i)
cout<<fixed<<setprecision(6)<<v[S[i]].first<<' '<<v[S[i]].second<<'\n';
return 0;
}