牛客算法周周练1 B 身体训练

B 身体训练

一道期望题,可以直接算出每个人的平均时间,然后求一个总和。
每个人的平均时间就是在哪一个位置,然后相对距离除以速度

code

#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
const int man = 2e5+10;
#define IOS ios::sync_with_stdio(0)
template <typename T>
inline T read(){T sum=0,fl=1;int ch=getchar();
for(;!isdigit(ch);ch=getchar())if(ch=='-')fl=-1;
for(;isdigit(ch);ch=getchar())sum=sum*10+ch-'0';
return sum*fl;}
template <typename T>
inline void write(T x) {static int sta[35];int top=0;
do{sta[top++]= x % 10, x /= 10;}while(x);
while (top) putchar(sta[--top] + 48);}
template<typename T>T gcd(T a, T b) {return b==0?a:gcd(b, a%b);}
template<typename T>T exgcd(T a,T b,T &g,T &x,T &y){if(!b){g = a,x = 1,y = 0;}
else {exgcd(b,a%b,g,y,x);y -= x*(a/b);}}
#ifndef ONLINE_JUDGE
#define debug(fmt, ...) {printf("debug ");printf(fmt,##__VA_ARGS__);puts("");}
#else
#define debug(fmt, ...)
#endif
typedef long long ll;
const ll mod = 1e9+7;
double c[man],d[man];

int main() {
    #ifndef ONLINE_JUDGE
        //freopen("in.txt", "r", stdin);
        //freopen("out.txt","w",stdout);
    #endif
    int n;
    double v,u;
    cin >> n >> v >> u;
    for(int i = 1;i <= n;i++){
        cin >> c[i];
    }
    for(int i = 1;i <= n;i++){
        cin >> d[i];
    }
    double sum = 0;
    for(int i = 1;i <= n;i++){//第几个人
        for(int j = 1;j <= n;j++){//第i个人的在第j轮
            sum += 1.0 * u / (c[i] - 1.0 * (j-1) * d[i] - v);
        }
    }
    printf("%.3lf\n",sum);
    return 0;
}   
原创文章 93 获赞 12 访问量 8993

猜你喜欢

转载自blog.csdn.net/weixin_43571920/article/details/105428924