Cod sursa(job #2736439)

Utilizator vansJos da pa perete vans Data 3 aprilie 2021 14:41:24
Problema Rays Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.9 kb
#include <bits/stdc++.h>

using namespace std;

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

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

int main()
{
    freopen("rays.in", "r", stdin);
    freopen("rays.out", "w", stdout);
    scanf("%d", &n);
    for(int i = 1; i <= n; ++i) {
        int x, y1, y2, vx;
        scanf("%d%d%d", &x, &y1, &y2),
        vx = (x > 0 ? x : -x);
        double unghi1 = atan2(y1, vx), unghi2 = atan2(y2, vx);
        if(unghi1 > unghi2) swap(unghi1, unghi2);
        if(x > 0) poz.push_back({unghi1, unghi2});
        else neg.push_back({unghi1, unghi2});
    }
    printf("%d", solve(poz) + solve(neg));
    return 0;
}