“今日头条杯”首届湖北省大学程序设计竞赛(网络同步赛)B. Salty Fish Go!

题目描述 

A few days ago, WRD was playing a small game called Salty Fish Go. We can simplify the rules of the game as follows.

The road can be abstracted into a one-dimensional axis, and the length of the road is L. There are two magic doors at the ends of the road, which can instantly transfer WRD from position L to position 0, or from location 0 to location L, without spending time.

WRD can select the initial position, the initial direction of movement, and the initial speed (from the speed set).

There are some amazing gas stations on the way, whose location is random. At the gas station WRD can change speed to one of the speed set, without spending time. (Do not change direction!)

There are some jewels on the road, whose location is random. WRD needs to take away all the jewels to win the game.

How long does it take WRD to win the game?

It’s an easy game. But considering that WRD has become a salty fish without brain, all his operations are completely random. Can you calculate the expected time for him to win the game?

输入描述:

 
  

Input contains multiple test cases, please process to the end of input.

For each test case, the first line of the input contains four positive integers V (), L (), n (), m () to indicate the size of speed set, the length of the road, the number of the gas stations, the number of the jewels.

Then, there are V integers in a line, the speed set, each integer is between 1 and .

输出描述:

The output is a real number, let your answer be a, and jury's answer be b, your answer will be considered as correct if and only if .
示例1

输入

2 8 1 1
2 4
2 8 1 1
2 4

输出

1.333333333
1.333333333

题意:

几天前,WRD正在玩一款名为Salty Fish Go的小游戏。我们可以按照以下方式简化游戏规则。
道路可以抽象为一维轴线,道路长度为L.在道路两端有两个魔术门,可以立即将WRD从位置L转移到位置0,或从位置0到位置0位置L,无需花时间。
WRD可以选择初始位置,初始运动方向和初始速度(从速度设置)。
途中有一些令人惊叹的加油站,其位置是随机的。在加油站,WRD可以将速度改变为设定的速度之一,而无需花时间。 (不要改变方向!)
路上有些珠宝,其位置是随机的。 WRD需要拿走所有的珠宝来赢得比赛。
WRD赢得比赛需要多长时间?
这是一个简单的游戏。但考虑到WRD已成为无脑的咸鱼,他的所有操作都是完全随机的。你能计算出他赢得比赛的预期时间吗?
输入描述:
输入包含多个测试用例,请处理至输入结束。
对于每个测试用例,输入的第一行包含四个正整数V(),L(),n(),m()来表示速度集的大小,道路的长度,加油站的数量,珠宝的数量。
然后,在一行中有V个整数,速度设置,每个整数在1和1之间。
输出描述:
输出是一个真实的数字,让你的答案是a,陪审团的答案是b,你的答案将被认为是正确的,当且仅当

思路:因为都是随机的,所有求出平均速度,平均路程,路程/时间就是预期时间了。。。。

ACDAIMA:

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
 
int v,l,n,m;
 
int main()
{
    while (scanf("%d%d%d%d",&v,&l,&n,&m)!=EOF)
    {
        double sum=0;
        for (int i=1;i<=v;++i)
        {
            int x;
            scanf("%d",&x);
            sum+=x;
        }
        sum/=v;
        double ans=1.0*m*l/(m+1);
        ans=ans/sum;
        printf("%.10f\n",ans);
    }
    return 0;
}



猜你喜欢

转载自blog.csdn.net/sugarbliss/article/details/80046217