Cod sursa(job #2628052)

Utilizator enedumitruene dumitru enedumitru Data 14 iunie 2020 11:03:02
Problema Rays Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.94 kb
#include <bits/stdc++.h>
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;
        unsigned dv=v.size();
		for(unsigned i=1; i<dv; ++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;
        unsigned du=u.size();
		for(unsigned i=1; i<du; ++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(); f.close(); return 0;
}