Cod sursa(job #2557971)

Utilizator suntbossgiani kirita suntboss Data 26 februarie 2020 10:26:49
Problema Rays Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.39 kb
#include <vector>
#include <fstream>
#include <iostream>
#include <cmath>
#include <map>
#include <algorithm>
#define ull unsigned long long int
#define error 0.000001
using namespace std;
ifstream f("rays.in");
ofstream g("rays.out");
int n;

vector<pair<double,double> > cadran1;
vector<pair <double, double> >cadran2;
int cnt1,cnt2;
int solve(vector<pair< double,double> > cadran)
{
    sort(cadran.begin(),cadran.end());
    int cnt=0,sol=0,start=0;
    for(int i=1;i<cadran.size();i++)
    {
       if(cadran[i].first>cadran[start].second)
       {
           cnt++;
           start=i;
       }
       else
       {
           if(cadran[i].second<cadran[start].second)
            start=i;
       }
    }
    cnt++;
    return cnt;
}
int main()
{
    f>>n;
    for(int i=1; i<=n; i++)
    {
        int x,y,y1;
        f>>x>>y>>y1;
        if(x<0)
        {
            double  unghi1=double (1.0*y/-x);
            double unghi2=double(1.0*y1/-x);
            if(unghi1>unghi2) swap(unghi1,unghi2);

            cadran2.push_back (make_pair(unghi1,unghi2));

        }
        else
        {
            double  unghi1=double (1.0*y/x);
            double unghi2=double(1.0*y1/x);
            if(unghi1>unghi2) swap(unghi1,unghi2);
            cadran1.push_back (make_pair (unghi1,unghi2));

        }

    }
    g<<solve(cadran1)+solve(cadran2);
}