Cod sursa(job #2169377)

Utilizator MarinPeptenaruMarin Vasile Peptenaru MarinPeptenaru Data 14 martie 2018 15:04:32
Problema Pachete Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.79 kb
#include <bits/stdc++.h>

using namespace std;
ifstream in("pachete.in");
ofstream out("pachete.out");
const int nx=50002;
struct punct
{
    long double x;
    long double y;
    long double p;
};
vector < punct > v1,v2,v3,v4;
punct sediu,a,o={0,0,0};
long double panta(punct a, punct b)
{
    long double y=b.y-a.y;
    long double x=b.x-a.x;
    if(x==0)
    {
        if(y>0) return numeric_limits < long double > :: max();
        if(y<0) return numeric_limits < long double > :: min();
    }
    return y/x;
}
bool crit(const punct &a, const punct &b)
{
    return a.p<b.p;
}
int n;
int main()
{
    in>>n;
    in>>sediu.x>>sediu.y;
    for(int i=1; i<=n; i++)
    {
        in>>a.x>>a.y;
        a.x-=sediu.x;
        a.y-=sediu.y;
        a.p=panta(o,a);
        if(a.x>=0 && a.y>=0) v1.push_back(a);
        else if(a.x<=0 && a.y>=0) v2.push_back(a);
        else if(a.x<=0 && a.y<=0) v3.push_back(a);
        else if(a.x>=0 && a.y<=0) v4.push_back(a);
    }
    int sol=0;
    if(!v1.empty())
    {
        sol++;
        sort(v1.begin(),v1.end(),crit);
        for(int i=0; i<v1.size()-1; i++)
            if(v1[i].p!=v1[i+1].p)
                sol++;
    }
    if(!v2.empty())
    {
        sol++;
        sort(v2.begin(),v2.end(),crit);
        for(int i=0; i<v2.size()-1; i++)
            if(v2[i].p!=v2[i+1].p)
                sol++;
    }
    if(!v3.empty())
    {
        sol++;
        sort(v3.begin(),v3.end(),crit);
        for(int i=0; i<v3.size()-1; i++)
            if(v3[i].p!=v3[i+1].p)
                sol++;
    }
    if(!v4.empty())
    {
        sol++;
        sort(v4.begin(),v4.end(),crit);
        for(int i=0; i<v4.size()-1; i++)
            if(v4[i].p!=v4[i+1].p)
                sol++;
    }
    out<<sol;
    return 0;
}