Cod sursa(job #3187969)

Utilizator radu._.21Radu Pelea radu._.21 Data 31 decembrie 2023 16:39:20
Problema Rays Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.16 kb
#include <bits/stdc++.h>

using namespace std;
vector<pair<double,double>>poz,neg;
bool cmp(pair<double,double> a,pair<double,double> b){
    return a.first < b.first;
}
ifstream fin("rays.in");
ofstream fout("rays.out");
int n;
int main(){
    fin>>n;
    for(int i=1;i<=n;i++){
        int x,y,y2; fin>>x>>y>>y2;
        if(y2<y)
            swap(y2,y);
        double u1 = atan2(y,abs(x));
        double u2 = atan2(y2,abs(x));
        if(x>=0)
        poz.push_back({u1,u2});
        else
        neg.push_back({u1,u2});
    }
     int rez = 0;

     sort(poz.begin(),poz.end(),cmp);
     sort(neg.begin(),neg.end(),cmp);
    rez+=2;
    double aux = poz[0].second;
    for(int i=1;i<poz.size();i++){
        double jos = poz[i].first;
        double sus = poz[i].second;
        if(jos < aux)
            aux = min(aux,sus);
        else
            rez++,aux = sus;
    }
    aux = neg[0].second;
    for(int i=1;i<neg.size();i++){
        double jos = neg[i].first;
        double sus = neg[i].second;
        if(jos < aux)
            aux = min(aux,sus);
        else
            rez++,aux = sus;
    }
    fout<<rez;
    return 0;
}