Cod sursa(job #3188744)

Utilizator Robert_NicuNicu Robert Cristian Robert_Nicu Data 3 ianuarie 2024 19:36:16
Problema Rays Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.02 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, bool> > v[2];

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

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

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,  0));
            v[0].push_back(make_pair(p2,  1));
        }else {
            v[1].push_back(make_pair(p1,  0));
            v[1].push_back(make_pair(p2, 1));
        }
    }
    sort(v[0].begin(), v[0].end(), comp);
    sort(v[1].begin(), v[1].end(), comp);
    rez(v[0]);
    rez(v[1]);
    fout<<ans;
}