Cod sursa(job #2785266)

Utilizator stefantagaTaga Stefan stefantaga Data 18 octombrie 2021 13:01:03
Problema Laser Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 2.08 kb
#include <bits/stdc++.h>
#define PI 3.14159265
using namespace std;
ifstream f("laser.in");
ofstream g("laser.out");
bitset < 1024 > din[1024];
int n,x,y,x2,y2,i,m,j,fr[1024],poz[1024];
long double unghi,unghi2;
pair <long double,long double> ceau[1024];
vector <long double> v,bisect;
bool eok(long double x,long double y,long double bisec)
{
    if (y-x>180)
    {
        return (bisec<=x||bisec>=y);
    }
    return (x<=bisec&&bisec<=y);
}
int main()
{
    f>>n;
    for (i=1;i<=n;i++)
    {
        f>>x>>y>>x2>>y2;
        unghi = atan2(y,x) * 180 / PI;
        unghi2 = atan2(y2,x2) * 180 / PI;
        if (unghi<0)
        {
            unghi+=360;
        }
        if (unghi2<0)
        {
            unghi2+=360;
        }
        if (unghi>unghi2)
        {
            swap(unghi,unghi2);
        }
        ceau[i]={unghi,unghi2};
        v.push_back(unghi);
        v.push_back(unghi2);
    }
    sort (v.begin(),v.end());
    m=v.size();
    for (i=0;i<m-1;i++)
    {
        bisect.push_back((v[i]+v[i+1]/2));
    }
    bisect.push_back((v[0]+360+v[m-1])/2);
    if (bisect.back()>360)
    {
        bisect.back()-=360;
    }
    for (i=1;i<=n;i++)
    {
        for (j=1;j<=m;j++)
        {
            din[i][j]=eok(ceau[i].first,ceau[i].second,bisect[j-1]);
        }
        bool x;
        f>>x;
        din[i][m+1]=x;
    }
    for (i=1;i<=n;i++)
    {
        j=0;
        for (j=1;j<=m+1;j++)
        {
            if (din[i][j]!=0)
            {
                break;
            }
        }
        if (j==m+2)
        {
            continue;
        }
        poz[i]=j;
        for (j=1;j<=n;j++)
        {
            if (i!=j&&din[j][poz[i]])
            {
                din[j]^=din[i];
            }
        }
    }
    vector <long double> sol;
    for (i=1;i<=n;i++)
    {
        if (poz[i]!=0&&din[i][m+1]!=0)
        {
            sol.push_back(bisect[poz[i]-1]);
        }
    }
    g<<(int)sol.size()<<'\n';
    for (i=0;i<sol.size();i++)
    {
        g<<sol[i]<<'\n';
    }
    return 0;
}