Pagini recente » Cod sursa (job #476877) | Cod sursa (job #1121850) | Cod sursa (job #1631375) | Cod sursa (job #219498) | Cod sursa (job #950160)
Cod sursa(job #950160)
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
ifstream f("rays.in"); ofstream g("rays.out");
struct segment {int x,y1,y2;};
vector <segment> v,u;
int n,nr;
inline int cmp(segment a, segment b)
{ return 1LL*a.x*b.y2>1LL*b.x*a.y2;}
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())
{ ++nr;
for(unsigned i=1; i<v.size(); ++i)
if(1LL*v[i-1].x*v[i].y1>1LL*v[i].x*v[i-1].y2) ++nr;
}
sort(u.begin(),u.end(),cmp);
if(u.size())
{ ++nr;
for(unsigned i=1; i<u.size(); ++i)
if(1LL*u[i-1].x*u[i].y1>1LL*u[i].x*u[i-1].y2) ++nr;
}
g<<nr<<'\n'; g.close(); return 0;
}