Codeforces 590B Chip 'n Dale Rescue Rangers(二分)

题目链接:Codeforces 590B Chip ‘n Dale Rescue Rangers

解题思路

二分时间,判断是否可行。判断方法为先处理出在风的作用下会移动到哪里,然后看最后用最大速度是否能到达目的地。

代码

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>

using namespace std;
const double eps = 1e-8;

double sx, sy, ex, ey;
double v, t;
double vx, vy, wx, wy;

bool judge (double h) {
    if (h > t) {
        sx = ex - vx * t - (h-t) * wx;
        sy = ey - vy * t - (h-t) * wy;
    } else {
        sx = ex - vx * h;
        sy = ey - vy * h;
    }
    return sx * sx + sy * sy <= v * v * h * h;
}

int main () {
    scanf("%lf%lf%lf%lf", &sx, &sy, &ex, &ey);
    scanf("%lf%lf", &v, &t);
    scanf("%lf%lf%lf%lf", &vx, &vy, &wx, &wy);
    ex -= sx, ey -= sy;

    double l = 0, r = 1e20;
    while (r - l > eps) {
        double mid = (l + r) * 0.5;
        if (judge(mid))
            r = mid;
        else
            l = mid;
    }
    printf("%.10lf\n", l);
    return 0;
}

你可能感兴趣的:(Codeforces 590B Chip 'n Dale Rescue Rangers(二分))