Pagini recente » Cod sursa (job #2635979) | Cod sursa (job #2456348) | Cod sursa (job #1151899) | Cod sursa (job #1861283) | Cod sursa (job #974858)
Cod sursa(job #974858)
#include<fstream>
#include<vector>
#include<algorithm>
using namespace std;
ifstream f("rays.in");
ofstream g("rays.out");
int i,n,nr,x,y;
struct seg{int x,y1,y2;};
seg nou;
vector<seg>p,ne;
inline bool cmp(seg a,seg b)
{
return (1LL*a.x*b.y2>1LL*a.y2*b.x);
}
int main()
{
f>>n;
for(i=1;i<=n;++i)
{
f>>nou.x>>nou.y1>>nou.y2;
if(nou.y1>nou.y2)
swap(nou.y1,nou.y2);
if(nou.x>0)
p.push_back(nou);
else
{
nou.x*=-1;
ne.push_back(nou);
}
}
sort(p.begin(),p.end(),cmp);
if(p.size())
{
++nr;
x=p[0].x;
y=p[0].y2;
for(i=1;i<p.size();++i)
if(1LL*x*p[i].y1>1LL*y*p[i].x)
{
++nr;
x=p[i].x;
y=p[i].y2;
}
}
sort(ne.begin(),ne.end(),cmp);
if(ne.size())
{
++nr;
x=ne[0].x;
y=ne[0].y2;
for(i=1;i<ne.size();++i)
if(1LL*x*ne[i].y1>1LL*y*ne[i].x)
{
++nr;
x=ne[i].x;
y=ne[i].y2;
}
}
g<<nr<<'\n';
}