Cod sursa(job #2405988)

Utilizator Alex_AeleneiAlex Aelenei Ioan Alex_Aelenei Data 15 aprilie 2019 11:43:51
Problema Rays Scor 60
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.62 kb
#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 read(void)
{
    char ch;
    int sign=1,nr=0;
    while(1)
    {
        scanf("%c",&ch);
        if(ch=='\n'||ch==' ')
            break;
        if(ch=='-')
            sign=-1;
        else
            nr=nr*10+(int)(ch-'0');
    }
    return nr*sign;
}
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;
    n=read();
    for(register int i=1;i<=n;i++)
    {
        x=read();
        y1=read();
        y2=read();
        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;
}