Cod sursa(job #3188903)

Utilizator PatruMihaiPatru Mihai PatruMihai Data 3 ianuarie 2024 23:40:23
Problema Rays Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.11 kb
#include <bits/stdc++.h>

using namespace std;

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

struct poz
{
    double x, y;
};

int nr;

void rez(vector<poz> x)
{
    sort(x.begin(), x.end(), [](const poz &a, const poz &b) {
        return a.x < b.x;
    });

    nr++;
    double dmin = x[0].x;
    double dmax = x[0].y;

    for (int i = 1; i < x.size(); i++)
    {
        double x1 = x[i].x;
        double y1 = x[i].y;

        if (x1 > dmax)
        {
            nr++;
            dmin = x1;
            dmax = y1;
        }

        if (x1 < dmax)
        {
            dmax = min(dmax, y1);
        }
    }
}

int main()
{
    int n, x, y, z;
    fin >> n;

    vector<poz> d;
    vector<poz> s;
    for (int i = 1; i <= n; i++)
    {
        fin >> x >> y >> z;
        double u1 = atan2(y, abs(x));
        double u2 = atan2(z, abs(x));

        if (u1 > u2)
        {
            swap(u1, u2);
        }
        if (x > 0)
        {
            d.push_back({u1, u2});
        }
        else
        {
            s.push_back({u1, u2});
        }
    }

    rez(d);
    rez(s);
    
    fout << nr;

    return 0;
}