zoukankan      html  css  js  c++  java
  • 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;
    }
    

      

  • 相关阅读:
    Android——编译odex保护
    【深入JVM内核—原理、诊断与优化】第2期开课了
    17周(引用做形參 )
    虚拟机设备直通的两种方式(Working in Progress)
    UVa 10256 The Great Divide,推断两个凸包是否相离
    awk 传入外部参数
    shell/bash 让vi/vim显示空格,及tab字符
    shell/bash 交集、并集、差集
    Windows XP搜索功能 "包含文字" 搜索不到内容的解决办法
    C语言字符串查找函数
  • 原文地址:https://www.cnblogs.com/tyty-Somnuspoppy/p/6386181.html
Copyright © 2011-2022 走看看