zoukankan      html  css  js  c++  java
  • UVA 12230 Crossing Rivers

    嘟嘟嘟

    虽然分类是期望dp,不过好像是最水的

    因为在陆地上的时间和概率是固定的,所以只用考虑过河的期望时间。

    对于一条河p, l, v,p好像没什么用……不管了,首先期望时间我觉得可以这么算:期望时间=期望距离 / 速度,又因为船停的位置和方向都是等概率随机的,所以期望的距离就是平均距离,很显然最长的距离是3L,最短是L,那么平均距离就是2L,期望时间就是2L / v。

    初始化ans = d,那么每一次ans = ans - L + 2L / v.

     1 #include<cstdio>
     2 #include<iostream>
     3 #include<cmath>
     4 #include<algorithm>
     5 #include<cstring>
     6 #include<cstdlib>
     7 #include<cctype>
     8 #include<vector>
     9 #include<stack>
    10 #include<queue>
    11 using namespace std;
    12 #define enter puts("") 
    13 #define space putchar(' ')
    14 #define Mem(a) memset(a, 0, sizeof(a))
    15 typedef long long ll;
    16 typedef double db;
    17 const int INF = 0x3f3f3f3f;
    18 const db eps = 1e-8;
    19 //const int maxn = ;
    20 inline ll read()
    21 {
    22     ll ans = 0;
    23     char ch = getchar(), last = ' ';
    24     while(!isdigit(ch)) {last = ch; ch = getchar();}
    25     while(isdigit(ch)) {ans = ans * 10 + ch - '0'; ch = getchar();}
    26     if(last == '-') ans = -ans;
    27     return ans;
    28 }
    29 inline void write(ll x)
    30 {
    31     if(x < 0) x = -x, putchar('-');
    32     if(x >= 10) write(x / 10);
    33     putchar(x % 10 + '0');
    34 } 
    35 
    36 int n, d, cnt = 0;
    37 
    38 int main()
    39 {
    40     while(scanf("%d%d", &n, &d) && (n || d))
    41     {
    42         db ans = d;
    43         for(int i = 1; i <= n; ++i)
    44         {
    45             int p = read(), l = read(), v = read();
    46             ans = ans - l + 2 * (db)l / (db)v;
    47         }
    48         printf("Case %d: %.3lf
    
    ", ++cnt, ans);
    49     }
    50     return 0;
    51 }
    View Code
  • 相关阅读:
    数据库02
    MySQL1
    GIL 死锁 递归锁 event 信号量 线程Queue
    小脚本 暴力删除文件 刷屏
    常见web攻击 及基础 回顾(杂记)
    接口中的简单异步 async
    python协程 示例
    python 利用jinja2模板生成html
    python 调用webservices 接口
    python 进程 进程池 进程间通信
  • 原文地址:https://www.cnblogs.com/mrclr/p/9635257.html
Copyright © 2011-2022 走看看