Pagini recente »
Cod sursă (job #579151)
|
Profil Sahisttul
|
Istoria paginii utilizator/lolkekzor
|
Istoria paginii utilizator/wi_bubblyt
|
Cod sursă (job #173422)
Cod sursă (job
#173422)
#include <fstream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <vector>
using namespace std;
ifstream cin ("infasuratoare.in");
ofstream cout ("infasuratoare.out");
/*struct pn{
double x,y;
}v[120010];*/
#define x first
#define y second
typedef pair <double,double> pn;
pn stk[120010],v[120010];;
double ccw(pn p1, pn p2, pn p3) // <0 dup acele cs // >0 impotriva acelor cs // =0 coliniare
{
return( (p2.x - p1.x)*(p3.y - p1.y) - (p2.y - p1.y)*(p3.x - p1.x) );
}
bool cmp(pn p1, pn p2){
return (ccw(v[1],p1,p2)<0);
}
int N, head;
///////////////////////////////////////////////////////////////////////////
int main() {
int poz=1;
cin >> N;
for(int i(1); i<=N; ++i){
cin >> v[i].x >> v[i].y;
// if( v[i].x<v[poz].x || (!(v[poz].x<v[i].x) && v[i].y<v[poz].y) ) poz=i;
if(v[i]<v[poz]) poz=i;
}
swap(v[1],v[poz]);
sort(v+2, v+N+1, cmp);
stk[1]=v[1]; stk[2]=v[2];
head=2;
for(int i=3; i<=N; ++i) {
while( (head>=2) && (ccw(stk[head-1],stk[head],v[i])>0) ) --head;
stk[++head]=v[i];
}
// cout << head << "\n";
cout << fixed;
vector<pn> rep (stk+1, stk+head+1);
// for(int i=head-1; i>=0; i--) cout << rep[i].x << " " << rep[i].y << "\n";
int i,j,k;
i=head-1; j=head-2; k=head-3;
/* while(i>-1) {
if( ccw(rep[i],rep[j],rep[k])==0 ) { rep.erase(rep.begin()+j); head--; cout << "sters\n";};
i--; j--; k--;
if(j==0) j=head-1;
if(k==0) k=head-1;
} */
head--;
for(int i=0; i<=head; i++) if( ccw(rep[i],rep[(i+1)%head],rep[(i+2)%head])==0 ) { rep.erase(rep.begin()+j); head--; cout << "sters\n";}
// cout << "\n\n\n\n";
cout << head << "\n";
for(int i=head-1; i>=0; i--) cout << rep[i].x << " " << rep[i].y << "\n";
// cout << ccw(rep[0], rep[head-1], rep[head-2]);
return 0;
}