Cod sursa(job #950646)

Utilizator vlad2309pascariu vlad vlad2309 Data 17 mai 2013 14:11:39
Problema Rays Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.86 kb
#include <fstream>
#include <algorithm>
using namespace std;
ifstream f("rays.in"); ofstream g("rays.out");
const int Nmax=200002;
struct segment {long long x,y1,y2;};
int n,nv,nu,nr;
long long X,Y;
segment v[Nmax],u[Nmax];
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[++nv]=seg; else {seg.x=-seg.x; u[++nu]=seg;}
    }
	if(nv)
	{	sort(v+1,v+nv+1,cmp);
		nr++; X=v[1].x,Y=v[1].y2;
		for(int i=2;i<=nv;++i)
			if(X*v[i].y1>Y*v[i].x) {nr++; X=v[i].x; Y=v[i].y2;}
	}
	if(nu)
	{	sort(u+1,u+nu+1,cmp);
		nr++; X=u[1].x,Y=u[1].y2;
		for(int i=2;i<=nu;++i)
			if(X*u[i].y1>Y*u[i].x) {nr++; X=u[i].x; Y=u[i].y2;}
	}
	g<<nr<<'\n'; g.close(); return 0;
}