Cod sursa(job #1520325)

Utilizator nimicLeoveanu Mihaita Alexandru nimic Data 8 noiembrie 2015 16:45:27
Problema Rays Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.13 kb
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
ifstream in("rays.in");
ofstream out("rays.out");

struct segm{
	long long x, y1, y2; 
};
int n, rasp;
vector <segm> vp, vn;
segm aux;
 
bool cmp(segm a, segm b)
{
    return (a.y2 * b.x < a.x * b.y2);
}
 
void rezolva(vector <segm> &v)
{
    sort (v.begin(), v.end(), cmp);

    if (!v.empty())
    {
        int x = v[0].x;
        int y = v[0].y2;

        rasp++;
        for(int i = 1; i<v.size(); i++)
        {
            if(y * v[i].x<x * v[i].y1) 
            {
                rasp++;
                x = v[i].x;
                y = v[i].y2;
            }
        }
    }
}
 
int main()
{
	int player_unu=0;

    in>>n;
    for (int i = 1; i<=n; i++)
    {
        in>>aux.x>>aux.y1>>aux.y2;
        if (aux.y1>aux.y2)
			swap(aux.y1, aux.y2);
        if (aux.x>0)
        {
            vp.push_back(aux);
        }
        else
        {
            aux.x *= -1;
            vn.push_back(aux);
        }
    }
     
    rezolva(vp);
    rezolva(vn);
     
    out<<rasp<<'\n';

    return 0;
}