Cod sursa(job #1527734)

Utilizator Alexa2001Alexa Tudose Alexa2001 Data 18 noiembrie 2015 17:53:40
Problema Rays Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.95 kb
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int X,Y1,Y2,n,i,ult,nr=0;
vector< pair<double,double> > V[2];
double x,y;

inline void solve(int x)
{
    sort(V[x].begin(),V[x].end());
    int i;ult=-(1<<30);
    for(i=0;i<V[x].size();++i)
    if(V[x][i].second>ult)
    {
        ult=V[x][i].first;
        ++nr;
    }
}

int main()
{
    freopen("rays.in","r",stdin);
    freopen("rays.out","w",stdout);

    scanf("%d",&n);
    for(i=1;i<=n;++i)
    {
        scanf("%d%d%d",&X,&Y1,&Y2);
        if(X<0)
        {
            x=(double)Y2/X;y=(double)Y1/X;
            if(x<y) V[0].push_back({y,x});
            else V[0].push_back({x,y});
        }
        else
        {
            x=(double)Y2/X;y=(double)Y1/X;
            if(x<y) V[1].push_back({y,x});
            else V[1].push_back({x,y});
        }
    }

    nr=0;
    solve(0);solve(1);
    printf("%d\n",nr);

    return 0;
}