Cod sursa(job #1990820)

Utilizator Dobricean_IoanDobricean Ionut Dobricean_Ioan Data 13 iunie 2017 19:41:24
Problema Infasuratoare convexa Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.06 kb
#include <fstream>
#include <iomanip>
#include <algorithm>
#define x second
#define y first
using namespace std;
ifstream fin("infasuratoare.in");
ofstream fout("infasuratoare.out");
int n,mipoz;
typedef pair <double, double> Punct;
Punct p[120010];
 int st[120005];
 int vf;
double determinant(Punct A, Punct B, Punct C)
{
    return (B.x - A.x) * (C.y - A.y) - (B.y - A.y) * (C.x - A.x);
}
  
int comp(Punct A, Punct B)
{if(determinant(p[1], A, B) < 0)
        return true;
return false;
     
 }
  
 void read()
 { fin >> n;
    for(int i = 1; i <= n; i++)
    {
        fin >> p[i].x >> p[i].y;
        if(p[i] < p[mipoz]) mipoz = i;
    }
 }
  
int main()
{
    read();
    swap(p[1], p[mipoz]);
    sort(p+ 2, p + n + 1, comp);
    st[++vf] = 1;
    for(int i = 2; i <= n; i++)
    {
        while(vf > 1 && determinant(p[st[vf-1]], p[st[vf]], p[i]) > 0) 
                vf--;
        st[++vf] = i;
    }
    fout << vf << '\n';
    while(vf)
    {
        fout <<setprecision(6)  << fixed << p[st[vf]].x << ' ' << p[st[vf]].y << '\n';
        vf--;
    }
    return 0;
    }