Cod sursa(job #3210131)

Utilizator not_anduAndu Scheusan not_andu Data 5 martie 2024 10:42:21
Problema Laser Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 2.61 kb
#include <bits/stdc++.h>

using namespace std;

#define INFILE "laser.in"
#define OUTFILE "laser.out"

const int N_MAX = 520;

struct Point {
    
    double x, y;

    Point() : x(0), y(0) {}
    Point(int _x, int _y) : x(_x), y(_y) {}

};

struct Segment {

    Point left, right;

    Segment() : left(0, 0), right(0, 0) {}
    Segment(Point _left, Point _right) : left(_left), right(_right) {}

};

short n;
bool states[N_MAX];
int p[N_MAX];
vector<double> angles, bisectors;
pair<double, double> segments[N_MAX];
bitset<2 * N_MAX> equation[2 * N_MAX];


double getAngle(Point a){
    double ans = atan2(a.y, a.x) * 180 / M_PI;
    if(ans < 0) ans += 360;
    return ans;
}

bool intersects(double left, double right, double angle){
    if(right - left > 180) return (angle < left || right < angle);
    return (left < angle && angle < right);
}

void solve(){

    cin >> n;
    for(int i = 0; i < n; ++i){

        Segment aux; cin >> aux.left.x >> aux.left.y >> aux.right.x >> aux.right.y;

        double angle1 = getAngle(aux.left);
        double angle2 = getAngle(aux.right);

        if(angle1 > angle2) swap(angle1, angle2);

        segments[i] = make_pair(angle1, angle2);
        angles.push_back(angle1);
        angles.push_back(angle2);

    }

    for(int i = 1; i <= n; ++i) cin >> states[i];
    
    sort(angles.begin(), angles.end());

    for(int i = 0; i < angles.size(); ++i){
        bisectors.push_back((angles[i] + angles[i + 1]) / 2.0);
    }

    bisectors.push_back((angles[0] + angles.back() + 360) / 2.0);
    if(bisectors.back() > 360) bisectors.back() -= 360;

    for(int i = 1; i <= n; ++i){
        equation[i][angles.size() + 1] = states[i];
        for(int j = 1; j <= angles.size(); ++j){
            equation[i][j] = intersects(segments[i].first, segments[i].second, bisectors[j - 1]);
        }
    }

    for(int i = 1; i <= n; ++i){

        int j = 1;
        bool ok = false;
        for(; j <= angles.size() && !ok; ++j){
            if(equation[i][j]) ok = true;
        }

        if(j = angles.size() + 2) continue;

        p[i] = j;

        for(int j = 1; j <= n; ++j){
            if(i != j && equation[j][p[i]]) equation[j] ^= equation[i];
        }

    }

    vector<double> ans;
    for(int i = 1; i <= n; ++i){
        if(p[i] != 0 && equation[i][angles.size() + 1] != 0) ans.push_back(bisectors[p[i] - 1]);
    }

    cout << ans.size() << '\n';
    for(auto &it : ans){
        cout << fixed << setprecision(10) << it << '\n';
    }

}

int main(){
    ios_base::sync_with_stdio(false);
    freopen(INFILE, "r", stdin);
    freopen(OUTFILE, "w", stdout);
    cin.tie(0), cout.tie(0);
    solve();
    return 0;
}