Pagini recente » Cod sursa (job #2331197) | Cod sursa (job #554062) | Cod sursa (job #22277) | Cod sursa (job #2321449) | Cod sursa (job #935552)
Cod sursa(job #935552)
#include<stdio.h>
#include<vector>
#include<algorithm>
#define x first
#define y second
#define EPS 1.e-14
using namespace std;
vector< pair<double , double> > v , b;
int n , x , y1 , y2;
inline int cmp(pair<double , double> a , pair<double , double> b)
{
return a.y - b.y < EPS;
}
double r;
int nr;
int main()
{
freopen("rays.in" , "r" , stdin);
freopen("rays.out" , "w" , stdout);
scanf("%d" , &n);
for(int i=1 ; i<=n ; ++i)
{
scanf("%d %d %d" , &x , &y1 , &y2);
if(y1 > y2)
swap(y1 , y2);
///calculez tg de unghiuri
if(x > 0)
v.push_back(make_pair( (double) 1.0000*y1/x , (double) 1.0000*y2/x));
else
b.push_back(make_pair( (double) -1.0000*y1/x , (double) -1.0000*y2/x));
}
sort(v.begin() , v.end() , cmp);
sort(b.begin() , b.end() , cmp);
reverse(b.begin() , b.end());
///acum fac greedy pe unghiuri ca la reactivi
/// pt v
r=b[0].y;
nr=1;
for(int i=1 ; i<b.size() ; ++i)
if(b[i].x - r > EPS)
++nr , r=b[i].y;
r=v[0].y;
nr++;
for(int i=1 ; i<v.size() ; ++i)
if(v[i].x - r > EPS)
++nr , r=v[i].y;
printf("%d\n" , nr);
return 0;
}