Cod sursa(job #2540655)

Utilizator theo2003Theodor Negrescu theo2003 Data 7 februarie 2020 14:08:40
Problema Rays Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.07 kb
#include <vector>
#include <fstream>
#include <algorithm>
using namespace std;
ifstream cin("rays.in");
ofstream cout("rays.out");
struct segment {
    long long int x, y1, y2;
};
vector<segment> left_, right_;
long long int solve(vector<segment> &s){
    sort(s.begin(), s.end(), [](segment a, segment b){
        return a.y1*b.x < a.x*b.y1;
    });
    long long int return_ = 1;
    pair<long long int, long long int> max_lower = {s[0].x, s[0].y2};
    for(int x = 1;x<s.size();x++){
        if(s[x].y1*max_lower.first > s[x].x*max_lower.second){
            return_++;
        }
        max_lower = {s[x].x, s[x].y2};
    }
    return return_;
}
int main() {
    //ios_base::sync_with_stdio(0);
    int n;
    cin>>n;
    for(int x = 0, a, b, c; x<n; x++) {
        cin>>a>>b>>c;
        if(b > c)
            swap(b, c);
        if(a < 0)
            left_.push_back(segment{-a, b, c});
        else
            right_.push_back(segment{a, b, c});
    }
    long long int result = solve(left_) + solve(right_);
    cout<<result<<endl;
    return 0;
}