Cod sursa(job #950187)

Utilizator enedumitruene dumitru enedumitru Data 16 mai 2013 01:04:12
Problema Rays Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.92 kb
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
ifstream f("rays.in"); ofstream g("rays.out");
struct segment {int x,y1,y2;};
int n,nr,X,Y;
vector <segment> v,u;
inline int cmp(const segment &a, const segment &b) 
{	if(1LL*a.x*b.y2>1LL*b.x*a.y2) return 1; else return 0;}
int main()
{   f>>n;
	while(n--) 
	{	segment seg;
		f>>seg.x>>seg.y1>>seg.y2;
		if(seg.y1>seg.y2) swap(seg.y1,seg.y2);
        if(seg.x>0) v.push_back(seg); else {seg.x=-seg.x; u.push_back(seg);}
    }
	sort(v.begin(),v.end(),cmp);
	if(v.size()!=0)
    {	++nr; X=v[0].x,Y=v[0].y2;
		for(unsigned i=1; i<v.size(); ++i)
			if(1LL*X*v[i].y1>1LL*Y*v[i].x) {nr++; X=v[i].x; Y=v[i].y2;}
	}
	sort(u.begin(),u.end(),cmp);
	if(u.size()!=0)
    {	++nr; X=u[0].x,Y=u[0].y2;
		for(unsigned i=1; i<u.size(); ++i)
			if(1LL*X*u[i].y1>1LL*Y*u[i].x) {nr++; X=u[i].x; Y=u[i].y2;}
	}
    g<<nr<<'\n'; g.close(); return 0;
}