Cod sursa(job #2714340)

Utilizator MateiAruxandeiMateiStefan MateiAruxandei Data 1 martie 2021 18:17:47
Problema Rays Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.96 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin("rays.in");
ofstream fout("rays.out");

vector<pair<double, double> > poz, neg;

int solve(vector<pair<double, double> > vec){
    sort(vec.begin(), vec.end());
    int rez = 0;
    double mn = vec[0].first - 1;
    for(int i = 0; i < (int)vec.size(); ++i){
        if(vec[i].first > mn){
            ++rez;
            mn = vec[i].second;
        }
        else mn = min(mn, vec[i].second);
    }
    return rez;
}

int main()
{
    int n;
    fin >> n;

    for(int i = 1; i <= n; ++i)
    {
        int x, y1, y2;
        fin >> x >> y1 >> y2;

        int xx = (x > 0 ? x : -x);
        double ang1 = atan2(y1, xx);
        double ang2 = atan2(y2, xx);
        if(ang1 > ang2)
            swap(ang1, ang2);

        if(x > 0)
            poz.push_back({ang1, ang2});
        else neg.push_back({ang1, ang2});
    }
    fout << solve(poz) + solve(neg) << '\n';
    return 0;
}