当前位置:网站首页>UVA 12230 – crossing rivers (probability) "suggested collection"

UVA 12230 – crossing rivers (probability) "suggested collection"

2022-07-07 21:05:00 Full stack programmer webmaster

Hello everyone , I meet you again , I'm the king of the whole stack .

Topic link :uva 12230 – Crossing Rivers

The main idea of the topic : A man goes to work in the company every day . Every time I pass N Rivers . The distance between home and company is D. The default speed on land is 1, give N Information about the river . Include starting coordinates p, Width L, And the speed of the ship .

The boat will go back and forth on both sides of the river . People reach the river bank is . The position of the ship is random ( Including direction ). Ask about the expected time for people to reach the company .

Their thinking : Time on land is fixed , Just calculate the time of each river separately . Because when people get to the shore , The position of the ship is random , So the waiting time [0,2L/v], The period is equal probability , So the time to cross a river is extremely (0+2∗Lv)2+Lv=2∗Lv

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

using namespace std;

int main () {
    int cas = 1;
    int N;
    double D, p, l, v;

    while (scanf("%d%lf", &N, &D) == 2 && (N || D)) {

        for (int i = 0; i < N; i++) {
            scanf("%lf%lf%lf", &p, &l, &v);
            D = D - l + 2 * l / v;
        }

        printf("Case %d: %.3lf\n\n", cas++, D);
     }
    return 0;
}

Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/116447.html Link to the original text :https://javaforall.cn

原网站

版权声明
本文为[Full stack programmer webmaster]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207071843026177.html

随机推荐