385D - Bear and Floodlight - CodeForces Solution


bitmasks dp geometry *2200

Please click on ads to support us..

C++ Code:

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <iomanip>

struct LightHouse {
    long double x_{0};
    long double y_{0};
    long double a_{0};
};

long double Dist(const LightHouse& lh, long double d, long double r) {
    if (d == r) {
        return r;
    }
    long double pi = std::acos(-1.0);
    long double rad = (pi * lh.a_) / 180.0;
    std::pair<long double, long double> p = std::make_pair((d - lh.x_) * std::cos(rad) + lh.y_ * std::sin(rad),
                                                           (d - lh.x_) * std::sin(rad) - lh.y_ * std::cos(rad));

    if (p.second > -1e-10) {
        return r;
    }

    p.first /= p.second;
    return std::min(std::max(lh.x_ - lh.y_ * p.first, d), r);
}

long double MaxPath(long double l, long double r, const std::vector<LightHouse>& v) {
    std::vector<long double> opt(1 << (v.size()), l);
    for (size_t i = 0; i < (1 << (v.size())); i++) {
        for (size_t j = 0; j < v.size(); j++) {
            if (!((i >> j) & 1)) {
                opt[(i | (1 << j))] = std::max(opt[(i | (1 << j))], Dist(v[j], opt[i], r));
            }
        }
    }
    return opt.back() - l;
}

int main() {
    size_t n = 0;
    std::cin >> n;
    long double l = 0;
    long double r = 0;
    std::cin >> l >> r;
    std::vector<LightHouse> v(n);
    for (size_t i = 0; i < n; i++) {
        std::cin >> v[i].x_ >> v[i].y_ >> v[i].a_;
    }
    std::cout << std::fixed;
    std::cout.precision(8);
    std::cout << MaxPath(l, r, v);
    return 0;
}


Comments

Submit
0 Comments
More Questions

148A - Insomnia cure
1650A - Deletions of Two Adjacent Letters
1512A - Spy Detected
282A - Bit++
69A - Young Physicist
1651A - Playoff
734A - Anton and Danik
1300B - Assigning to Classes
1647A - Madoka and Math Dad
710A - King Moves
1131A - Sea Battle
118A - String Task
236A - Boy or Girl
271A - Beautiful Year
520B - Two Buttons
231A - Team
479C - Exams
1030A - In Search of an Easy Problem
158A - Next Round
71A - Way Too Long Words
160A - Twins
1A - Theatre Square
1614B - Divan and a New Project
791A - Bear and Big Brother
1452A - Robot Program
344A - Magnets
96A - Football
702B - Powers of Two
1036A - Function Height
443A - Anton and Letters