题目链接:https://vjudge.net/problem/LightOJ-1321

1321 - Sending Packets
Time Limit: 2 second(s) Memory Limit: 32 MB

Alice and Bob are trying to communicate through the internet. Just assume that there are N routers in the internet and they are numbered from 0 to N-1. Alice is directly connected to router 0 and Bob is directly connected to router N-1. Alice initiates the connection and she wants to send S KB of data to Bob. Data can go to the (N-1)th router from the 0th router either directly or via some intermediate routers. There are some bidirectional links between some routers.

The links between the routers are not necessarily 100% perfect. So, for each link, a probability pi is given. That means if u and v are two routers and if their underlying link has probability pi, it means that if data is sent from u to v, the probability of successfully getting the data in v is pi and vice versa. If multiple links are used the probability of getting the data in destination is the multiplication of the probabilities of the links that have been used.

Assume that it takes exactly K seconds for a packet to reach Bob's router from Alice's router (independent on the number of links) if it's successful. And when the data is successfully received in Bob's router, it immediately sends an acknowledgement to Alice's router and the acknowledgement always reaches her router exactly in K seconds (it never disappears).

Alice's router used the following algorithm for the data communication.

1)      At time 0, the first KB of data is chosen to be sent.

2)      It establishes a path (it takes no time) to the destination router and sends the data in this route.

3)      It waits for exactly 2K seconds.

  1. If it gets the acknowledgement of the current data in this interval
    1. i.      If S KB of data are sent, then step 4 is followed.
    2. ii.      Otherwise, it takes 1 KB of the next data, and then step 2 is followed.
  2. Otherwise it resends the current 1 KB of data and then step 2 is followed.

4)      All the data are sent, so it reports Alice.

Assume that the probabilities of the links are static and independent. That means it doesn't depend on the result of the previously sent data. Now your task is to choose some routes through the routers such that data can be sent in these routes and the expected time to send all the data to the destination routes is minimized. You only have to report the minimum expected time.

Input

Input starts with an integer T (≤ 100), denoting the number of test cases.

Each case starts with a line containing four integers N (2 ≤ N ≤ 100)M (1 ≤ M)S (1 ≤ S ≤ 109) and K (1 ≤ K ≤ 20), where M denotes the number of bidirectional links. Each of the next M lines contains three integers ui vi pi, meaning that there is a link between router ui and vi the probability for a successful message transfer in this link is pi% (0 ≤ ui, vi < N, ui ≠ vi, 0 < pi ≤ 100). There will be at most one link between two routers.

Output

For each case, print the case number and the minimum possible expected time to send all the data. Errors less than 10-3 will be ignored. You can assume that at least one valid route between them always exists. And the result will be less than 1013.

Sample Input

Output for Sample Input

2

5 5 1 10

0 1 70

0 2 40

2 3 100

1 3 50

4 3 80

2 1 30 2

0 1 80

Case 1: 62.5000000000

Case 2: 150

Note

For sample 1, we get the following picture. We send the data through 0 - 2 - 3 - 4.

题意:

给出一张图,从0到n-1传输s个包,传输的时候每条边正常运作的概率为pi,每次传输的时间为2K。如果能够运到终点,则还需从终点回到起始点;如果不能运到终点,则要从当前点返回到起始点(走过的路确保畅通),然后继续运送。每次往返的固定时间为2K,求最小的传送时间。

题解:

1. 用最短路算法求出从起点到终点的最大概率p。

2 先求出运输单个包所用的平均时间:EX = p*2K + (1-p)*(2K+EX),移项得:EX = 2K/p。再乘上s个,则答案为:2K*s/p 。

代码如下:

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <set>
using namespace std;
typedef long long LL;
const double EPS = 1e-;
const int INF = 2e9;
const LL LNF = 9e18;
const int MOD = 1e5;
const int MAXN = 1e2+; double g[MAXN][MAXN]; queue<int>Q;
double dis[MAXN], in[MAXN];
double spfa(int n)
{
memset(dis, , sizeof(dis));
memset(in, , sizeof(in));
while(!Q.empty()) Q.pop(); dis[] = 1.0;
Q.push();
while(!Q.empty())
{
int u = Q.front();
Q.pop();
in[u] = false;
for(int v = ; v<n; v++)
{
if(dis[v]<dis[u]*g[u][v])
{
dis[v] = dis[u]*g[u][v];
if(!in[v])
{
in[v] = true;
Q.push(v);
}
}
}
}
return dis[n-];
} int main()
{
int T, kase = ;
int n, m, k, s;
scanf("%d", &T);
while(T--)
{
scanf("%d%d%d%d", &n,&m,&k,&s);
memset(g, , sizeof(g));
while(m--)
{
int u, v, w;
scanf("%d%d%d", &u,&v,&w);
g[u][v] = g[v][u] = 0.01*w;
} double p = spfa(n);
double ans = 2.0*k/p*s;
printf("Case %d: %.8lf\n", ++kase, ans);
}
}

LightOJ - 1321 Sending Packets —— 概率期望的更多相关文章

  1. LightOJ 1321 - Sending Packets 简单最短路+期望

    http://www.lightoj.com/volume_showproblem.php?problem=1321 题意:每条边都有概率无法经过,但可以重新尝试,现给出成功率,传输次数和传输时间,求 ...

  2. LightOJ 1030 Discovering Gold (概率/期望DP)

    题目链接:LightOJ - 1030 Description You are in a cave, a long cave! The cave can be represented by a \(1 ...

  3. kuangbin 带你飞 概率期望

    正推不行就逆推! 经典问题:生日悖论 换成其互斥事件:m个人, 每个人生日都不相同的概率 ≤ 0.5 时最小人数. 这就是邮票收集问题的变形:每个邮票至少出现一次的概率 小于等于 0.5 邮票收集问题 ...

  4. 【BZOJ-1419】Red is good 概率期望DP

    1419: Red is good Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 660  Solved: 257[Submit][Status][Di ...

  5. uvalive 7331 Hovering Hornet 半平面交+概率期望

    题意:一个骰子在一个人正方形内,蜜蜂在任意一个位置可以出现,问看到点数的期望. 思路:半平面交+概率期望 #include<cstdio> #include<cstring> ...

  6. OI队内测试一【数论概率期望】

    版权声明:未经本人允许,擅自转载,一旦发现将严肃处理,情节严重者,将追究法律责任! 序:代码部分待更[因为在家写博客,代码保存在机房] 测试分数:110 本应分数:160 改完分数:200 T1: 题 ...

  7. 2016 多校联赛7 Balls and Boxes(概率期望)

    Mr. Chopsticks is interested in random phenomena, and he conducts an experiment to study randomness. ...

  8. 牛客网多校赛第9场 E-Music Game【概率期望】【逆元】

    链接:https://www.nowcoder.com/acm/contest/147/E 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524 ...

  9. 【bzoj4832】[Lydsy2017年4月月赛]抵制克苏恩 概率期望dp

    题目描述 你分别有a.b.c个血量为1.2.3的奴隶主,假设英雄血量无限,问:如果对面下出一个K点攻击力的克苏恩,你的英雄期望会受到到多少伤害. 输入 输入包含多局游戏. 第一行包含一个整数 T (T ...

随机推荐

  1. c# 推荐5款超实用的.NET性能分析工具

    虽然.NET框架号称永远不会发生内存泄漏,原因是引入了内存回收机制.但在实际应用中,往往我们分配了对象但没有释放指向该对象的引用,导致对象永远无法释放.最常见的情况就是给对象添加了事件处理函数,但当不 ...

  2. 让heigh:100%起作用

    如何让 height:100%; 起作用 http://www.webhek.com/css-100-percent-height     当你设置一个页面元素的高度(height)为100%时,期望 ...

  3. 1BIT,1BYTE,1KB,1MB,1GB,1TB等计量单位换算

    http://iask.sina.com.cn/b/8961090.html知识   在数字世界里没有电影.没有杂志.没有一首首的乐曲,只有一个个的数字“1”和“0”.以前人们对于数字世界中的这两个数 ...

  4. Mode Standby

    Modern Standby 1.Connected Standby和 Connected Standby是Windows 8全新的电源管理系统,即当系统进入休眠状态时,应用程式虽处於暂停(suspe ...

  5. Spring 中StreamUtils教程

    本文我们介绍StreamUtils类使用.StreamUtils是spring中用于处理流的类,是java.io包中inputStream和outputStream,不是java8中Steam.使用时 ...

  6. CentOS 配置网络

    1.编辑ifcfg-eth0 vi /etc/sysconfig/network-scripts/ifcfg-eth0 2.修改NOBOOT=yes 3.重启服务 service network re ...

  7. 架构 -- java

    @.sql写在dao层 原文:http://blog.csdn.net/y_dzaichirou/article/details/53673528 @.Java Web项目需要掌握的技能 原文:htt ...

  8. os引导程序boot从扇区拷贝os加载程序loader文件到内存(boot copy kernel to mem in the same method)

    [0]README 0.1) 本代码旨在演示 在boot 代码中,如何 通过 loader文件所在根目录条目 找出该文件的 在 软盘所有全局扇区号(簇号),并执行内存中的 loader 代码: 0.2 ...

  9. grok表达式

    grok表达式 grok其实就是封装了各种常用的正则表达式,屏蔽了直接写正则的复杂性:通过它可以提取日志内容,按照自己指定的格式输出到kibana. http://udn.yyuap.com/doc/ ...

  10. 九度OJ 1162:I Wanna Go Home(我想回家) (最短路径)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:870 解决:415 题目描述: The country is facing a terrible civil war----cities i ...