Cod sursa(job #3188781)

Utilizator Robert_NicuNicu Robert Cristian Robert_Nicu Data 3 ianuarie 2024 20:19:03
Problema Rays Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.01 kb
#include <bits/stdc++.h>
#define DIM 400001
#define y1 qwerty
#define y2 asdfgh
using namespace std;

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

int n, i, j, ans;
double x, y1, y2, p1, p2;
vector <pair <double, double> > v[2];

bool comp(pair <double, double> a, pair <double, double> b){
    return (a.first<b.first);
}

void rez(vector <pair <double, double> > a){
    double current=a[0].first;
    if(!a.empty())
        ans++;
    for(int i=1; i<a.size(); i++)
        if(a[i].second>current){
            ans++;
            current=a[i].first;
        }
}

int main(){
    fin>>n;
    for(i=1; i<=n; i++){
        fin>>x>>y1>>y2;
        p1=y1/x;
        p2=y2/x;
        if(p1<p2)
            swap(p1, p2);
        if(x<0)
            v[0].push_back(make_pair(p1,  p2));
        else
            v[1].push_back(make_pair(p1,  p2));
    }
    sort(v[0].begin(), v[0].end(), comp);
    sort(v[1].begin(), v[1].end(), comp);
    rez(v[0]);
    rez(v[1]);
    fout<<ans;
}