Pagini recente » Cod sursa (job #545190) | Cod sursa (job #1436608) | Cod sursa (job #6365) | Cod sursa (job #2440810) | Cod sursa (job #2405980)
#include<cstdio>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std;
const double PI=2.0*acos(0.0);
const double eps=4e-15;
double unghi(int x, int y)
{
double rad=1.0*atan2(1.0*y,1.0*x);
// if(rad<0) rad+=2 * PI;
return rad * 180 / PI;
}
struct mem
{
double unghi;
bool tip;
int ind;
};
mem v[400005];
int poz[200005];
bool cmp(mem a, mem b)
{
if(fabs(a.unghi-b.unghi)<eps) return a.tip>b.tip;
return a.unghi-b.unghi<-eps;
}
int main()
{
freopen("rays.in","r",stdin);
freopen("rays.out","w",stdout);
int h,n,x,y1,y2,cnt=0,cnta=0,act=0,gloante=0;
double u1,u2;
scanf("%d",&n);
for(register int i=1;i<=n;i++)
{
scanf("%d%d%d",&x,&y1,&y2);
h=2*i;
v[h-1].unghi=unghi(x,y1);
v[h].unghi=unghi(x,y2);
if(v[h].unghi-v[h-1].unghi<-eps) swap(v[h-1].unghi,v[h].unghi);
v[h-1].ind=v[h].ind=i;
v[h-1].tip=1;
v[h].tip=0;
}
sort(v+1,v+2*n+1,cmp);
for(register int i=1;i<=2*n;i++)
{
if(v[i].tip==1) cnt++;
else if(poz[v[i].ind]>act) cnt--;
poz[v[i].ind]=act+1;
if(cnt<cnta)
{
gloante++;
act++;
cnt=0;
}
cnta=cnt;
}
printf("%d",gloante);
return 0;
}