10.6 test problem-solving report

T1

Ideas:
half, the final answer time, and then half check when opening an array of deposit at the current boat finally off to reach the
target position, the position of the head of a ship is the second assigned time ride on his speed.

Behind the boat should consider the front of the ship is not blocking him.
If the front of the ship can be in front of him that is.
The two cases.
One is the current speed of the ship faster than the front of the boat when.
In front of the boat the final distance plus the captain in front of the ship.

The second is the current boat is slower than the front of the boat when.
And a maximum distance from the waistline is subtracted from the start it running to take a max.
Because he was blocking the front, of course, to take a max.

Distance is not obtained then the (1e-3) in one of the accuracy error.

#include <bits/stdc++.h>

#define N 100010
#define ll long long

using namespace std;
double l[N], v[N], x[N], a[N];
int n;

ll read() {
    ll s = 0, f = 0; char ch = getchar();
    while (!isdigit(ch)) f |= (ch == '-'), ch = getchar();
    while (isdigit(ch)) s = s * 10 + (ch ^ 48), ch = getchar();
    return f ? -s : s;
}

bool check(double tim) {
    for (int i = 0; i <= n; i++) a[i] = x[i];
    a[n] = a[n] - tim * v[n];
    for (int i = n - 1; i >= 0; i--) {
        double ddd = tim * v[i];
        a[i] = max(a[i] - ddd, a[i + 1] + l[i + 1]);
        if (a[i] > 1e-3) return false;
    }
    return true;
}

int main() {
//  freopen("cruise.in", "r", stdin);
//  freopen("cruise.out", "w", stdout);
    int T = read();
    while (T--) {
        n = read();
        for (int i = 0; i <= n; i++) l[i] = read();
        for (int i = 0; i <= n; i++) x[i] = read();
        for (int i = 0; i <= n; i++) v[i] = read();
        double l = 0, r = 1000000000;
        while (r - l > 1e-5) {
            double mid = (r + l) / 2.0;
            if (check(mid)) r = mid;
            else l = mid;
        }
        printf("%.5lf\n", r);
    }
}

Guess you like

Origin www.cnblogs.com/zzz-hhh/p/11627341.html