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

119A - Epic Game
703A - Mishka and Game
1504C - Balance the Bits
988A - Diverse Team
1312B - Bogosort
1616B - Mirror in the String
1660C - Get an Even String
489B - BerSU Ball
977C - Less or Equal
1505C - Fibonacci Words
1660A - Vasya and Coins
1660E - Matrix and Shifts
1293B - JOE is on TV
1584A - Mathematical Addition
1660B - Vlad and Candies
1472C - Long Jumps
1293D - Aroma's Search
918A - Eleven
1237A - Balanced Rating Changes
1616A - Integer Diversity
1627B - Not Sitting
1663C - Pōja Verdon
1497A - Meximization
1633B - Minority
688B - Lovely Palindromes
66B - Petya and Countryside
1557B - Moamen and k-subarrays
540A - Combination Lock
1553C - Penalty
1474E - What Is It