Pagini recente » Cod sursa (job #428360) | Cod sursa (job #738424) | Cod sursa (job #108679) | Cod sursa (job #2400154) | Cod sursa (job #2835622)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("infasuratoare.in");
ofstream fout("infasuratoare.out");
const int dim=200000;
struct pt{
long double x,y;
int ind;
bool operator <(const pt &other) const
{
if(x==other.x){
return y<other.y;
}
return x<other.x;
}
}v[dim];
int ap[dim],stiva[dim],vf;
vector<pt>e;
bool cross(pt a,pt b,pt c){
return (b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x)<=0;
}
void solve(){
vf=0;
for(auto it:e){
long double y=it.y;
int ind=it.ind;
while(vf>=2 && cross(v[stiva[vf-1]],v[stiva[vf]],v[ind])){
ap[stiva[vf]]--;
vf--;
}
stiva[++vf]=ind;
ap[ind]++;
}
vf=0;
reverse(e.begin(),e.end());
for(auto it:e){
long double y=it.y;
int ind=it.ind;
while(vf>=2 && cross(v[stiva[vf-1]],v[stiva[vf]],v[ind])){
ap[stiva[vf]]--;
vf--;
}
stiva[++vf]=ind;
ap[ind]++;
}
}
signed main(){
int n;
fin>>n;
for(int i=1;i<=n;i++){
fin>>v[i].x>>v[i].y;
e.push_back({v[i].x,v[i].y,i});
}
sort(e.begin(),e.end());
solve();
int nr=0;
for(int i=1;i<=n;i++){
if(ap[i]){
nr++;
}
}
fout<<nr<<'\n';
for(int i=1;i<=n;i++){
if(ap[i]){
fout<<fixed<<setprecision(12)<<v[i].x<<' '<<v[i].y<<'\n';
}
}
}