• UVA 12230 Crossing Rivers(过河)(期望)


    题意:从A到B需要经过n条河,已知AB间距离D和每条河的长度L以及在该条河上的船速v,求A到B平均情况下需多长时间。陆地行走速度为1,船的位置和朝向均匀随机。

    分析:

    1、过一条河,最短时间L/v(无需等船),最长时间3L/v(要坐船时,船正好驶离自己所在的河岸),所以平均时间为2L/v。

    2、再算出陆地行走距离,D-sum[L],求出陆地行走时间。

    #pragma comment(linker, "/STACK:102400000, 102400000")
    #include<cstdio>
    #include<cstring>
    #include<cstdlib>
    #include<cctype>
    #include<cmath>
    #include<iostream>
    #include<sstream>
    #include<iterator>
    #include<algorithm>
    #include<string>
    #include<vector>
    #include<set>
    #include<map>
    #include<stack>
    #include<deque>
    #include<queue>
    #include<list>
    #define Min(a, b) ((a < b) ? a : b)
    #define Max(a, b) ((a < b) ? b : a)
    const double eps = 1e-8;
    inline int dcmp(double a, double b) {
        if(fabs(a - b) < eps)  return 0;
        return a < b ? -1 : 1;
    }
    typedef long long LL;
    typedef unsigned long long ULL;
    const int INT_INF = 0x3f3f3f3f;
    const int INT_M_INF = 0x7f7f7f7f;
    const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
    const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
    const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
    const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
    const int MOD = 1e9 + 7;
    const double pi = acos(-1.0);
    const int MAXN = 1000 + 10;
    const int MAXT = 10000 + 10;
    using namespace std;
    int main(){
        int n, D;
        int kase = 0;
        while(scanf("%d%d", &n, &D) == 2){
            if(!n && !D) return 0;
            int sum = 0;
            double ans = 0;
            for(int i = 0; i < n; ++i){
                int p, L, v;
                scanf("%d%d%d", &p, &L, &v);
                sum += L;
                ans += double(2 * L) / v;
            }
            ans += D - sum;
            printf("Case %d: %.3lf\n\n", ++kase, ans);
        }
        return 0;
    }
    

      

  • 相关阅读:
    python爬虫requests json与字典对象互相转换
    python爬虫requests的使用
    Django 使用celery任务队列的配置
    Django实现发邮件
    leetcode算法:Two Sum II
    Python中使用hashlib进行加密的简单使用
    leetcode算法: Average of Levels in Binary Tree
    Django中自定义过滤器的使用
    linux下git常用命令
    cocos2d-x 父节点和子节点执行不同动作
  • 原文地址:https://www.cnblogs.com/tyty-Somnuspoppy/p/6386181.html
Copyright © 2020-2023  润新知