Cod sursa(job #1743582)

Utilizator fanache99Constantin-Buliga Stefan fanache99 Data 18 august 2016 13:50:01
Problema Rays Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.4 kb
#include <fstream>
#include <algorithm>
#include <vector>
using namespace std;

ifstream cin("rays.in");
ofstream cout("rays.out");

struct Segment {
    int x, y1, y2;
};

vector<Segment> a, b;

bool Compare(const Segment &a, const Segment &b) {
    return 1LL * a.x * b.y2 > 1LL * b.x * a.y2;
}

int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        Segment now;
        cin >> now.x >> now.y1 >> now.y2;
        if (now.y1 > now.y2)
            swap(now.y1, now.y2);
        if (now.x > 0)
            a.push_back(now);
        else {
            now.x = -now.x;
            b.push_back(now);
        }
    }
    int answer = 0;
    sort(a.begin(), a.end(), Compare);
    if (a.size() != 0) {
        answer++;
        int x = a[0].x;
        int y = a[0].y2;
        for (int i = 1; i < a.size(); i++)
            if (1LL * x * a[i].y1 > 1LL * y * a[i].x) {
                answer++;
                x = a[i].x;
                y = a[i].y2;
            }
    }
    sort(b.begin(), b.end(), Compare);
    if (b.size() != 0) {
        answer++;
        int x = b[0].x;
        int y = b[0].y2;
        for (int i = 1; i < b.size(); i++)
            if (1LL * x * b[i].y1 > 1LL * y * b[i].x) {
                answer++;
                x = b[i].x;
                y = b[i].y2;
            }
    }
    cout << answer << "\n";
    return 0;
}