Pagini recente » Cod sursa (job #2199731) | Cod sursa (job #966429) | Cod sursa (job #2103702) | Cod sursa (job #1694979) | Cod sursa (job #2076525)
#include <cstdio>
#include <algorithm>
#include <cmath>
const double eps=1.e-14;
using namespace std;
struct seg
{
double x,y;
};
seg stanga[200005];
seg dreapta[200005];
bool cmp(seg a, seg b)
{
if (fabs(a.x-b.x)<eps)
return a.y<b.y;
return a.x<b.x;
}
int main()
{
freopen("rays.in", "r",stdin);
freopen("rays.out", "w",stdout);
int n, i, j1, j2, x, y1, y2, nr;
double dr, st;
scanf("%d", &n);
j1=0;
j2=0;
for(i=1; i<=n; i++)
{
scanf("%d%d%d", &x, &y1, &y2);
if(x<0)
{
x*=-1;
if(y1<=y2)
{
stanga[++j1].x=(double)y1/x;
stanga[j1].y=(double)y2/x;
}
else
{
stanga[++j1].x=(double)y2/x;
stanga[j1].y=(double)y1/x;
}
}
else
{
if(y1<=y2)
{
dreapta[++j2].x=(double)y1/x;
dreapta[j2].y=(double)y2/x;
}
else
{
dreapta[++j2].x=(double)y2/x;
dreapta[j2].y=(double)y1/x;
}
}
}
sort(stanga+1, stanga+j1+1,cmp);
sort(dreapta+1, dreapta+j2+1,cmp);
if(j1>0)
nr=1;
st=stanga[1].x;
dr=stanga[1].y;
for(i=2; i<=j1; i++)
{
if(stanga[i].x<=dr)
{
st=stanga[i].x;
dr=min(dr, stanga[i].y);
}
else
{
nr++;
st=stanga[i].x;
dr=stanga[i].y;
}
}
if(j2>0)
nr++;
st=dreapta[1].x;
dr=dreapta[1].y;
for(i=2; i<=j2; i++)
{
if(dreapta[i].x<=dr)
{
st=dreapta[i].x;
dr=min(dr, dreapta[i].y);
}
else
{
nr++;
st=dreapta[i].x;
dr=dreapta[i].y;
}
}
printf("%d", nr);
return 0;
}