HDU6581 Vacation (HDU2019 first multi-school 1004)

HDU6581 Vacation (HDU2019 first multi-school 1004)

Portal: http://acm.hdu.edu.cn/showproblem.php?pid=6581

Meaning of the questions:

N + 1 to your vehicles, each vehicle car having a length L, a distance from the finish automobile S, the maximum vehicle speed V

When 0, large speed equal to the speed of the car will speed small car distance between the car and the car's speed

Seeking the end furthest from the front of the car to reach the end time

Note that when the car passing the finish line will continue to travel, meet, on the back of the car also affects

answer:

Here to talk about O (n) the wording

First, when the last car we will not meet with other cars, we can get an answer to s [0] / v [0];

Then, we assume that all cars have met the situation

As shown, just reaches the end of the last car, and to meet the number of the second car, the same time, n + 1 which are now all in vehicle speed of the first car v [n] with, we it is also very easy to obtain, and finally a time to reach the front end of the car is exactly the time the first car to reach the position pos

\(t=(\sum_{1}^{n}L_i+sn)/v_n\)

With these two limiting cases we can think, if our last car collided with a car in front of any of our last car to reach the end of the last time are collided with the car to the front calculated, each additional hit a car will slow down our response time, which is larger, so we saved the maximum value of a car is the last meet of the time, as shown, even if I have to the bottom third of the car even if the answer

Code:

#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef unsigned long long uLL;
#define ls rt<<1
#define rs rt<<1|1
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define bug printf("*********\n")
#define FIN freopen("input.txt","r",stdin);
#define FON freopen("output.txt","w+",stdout);
#define IO ios::sync_with_stdio(false),cin.tie(0)
#define debug1(x) cout<<"["<<#x<<" "<<(x)<<"]\n"
#define debug2(x,y) cout<<"["<<#x<<" "<<(x)<<" "<<#y<<" "<<(y)<<"]\n"
#define debug3(x,y,z) cout<<"["<<#x<<" "<<(x)<<" "<<#y<<" "<<(y)<<" "<<#z<<" "<<z<<"]\n"
const int maxn = 3e5 + 5;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
LL quick_pow(LL x, LL y) {
    LL ans = 1;
    while(y) {
        if(y & 1) {
            ans = ans * x % mod;
        } x = x * x % mod;
        y >>= 1;
    } return ans;
}
int l[maxn], s[maxn], v[maxn];
int main() {
#ifndef ONLINE_JUDGE
    FIN
#endif
    int n;
    while(~scanf("%d", &n)) {
        for(int i = 0; i <= n; i++) scanf("%d", &l[i]);
        for(int i = 0; i <= n; i++) scanf("%d", &s[i]);
        for(int i = 0; i <= n; i++) scanf("%d", &v[i]);
        double ans = s[0] * 1.0 / v[0];
        int sum = 0;
        for(int i = 1; i <= n; i++) {
            sum += l[i];
            ans = max(ans, (sum + s[i]) * 1.0 / v[i]);
        }
        printf("%.10f\n", ans);
    }
    return 0;
}

Guess you like

Origin www.cnblogs.com/buerdepepeqi/p/11229427.html