题目链接: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. 《学习bash》笔记--调试shell程序

    在shell中,最简单的调试助手时输出语句echo,能够通过把很多echo语句放到代码中进行调试,但必须花费足够的时间以定位 要查看的信息.可能必须通过很多的输出才干发现要查找的信息. 1.set选项 ...

  2. 96Boards扩展板 STM32 B96B-F446VE 牛刀小试

    前言 原创文章,转载引用务必注明链接,水平有限,如有疏漏,欢迎指正. 本文使用Markdown写成,为获得更好的阅读体验和正常的链接.图片显示,请访问我的博客原文: http://www.cnblog ...

  3. The network connection was lost 文件下载错误提示

    假设出现这种错误,可能是模拟器断网,重新启动下模拟器就能够:The network connection was lost

  4. 自己定义字体之BMFont的使用

    ***************************************转载请注明出处:http://blog.csdn.net/lttree************************** ...

  5. 【转载】关于 .Net 逆向的那些工具:反编译篇

    在项目开发过程中,估计也有人和我遇到过同样的经历:生产环境出现了重大Bug亟需解决,而偏偏就在这时仓库中的代码却不是最新的.在这种情况下,我们不能直接在当前的代码中修改这个Bug然后发布,这会导致更严 ...

  6. 有两个好友A和B,住在一片长有蘑菇的由n*m个方格组成的草地,A在(1,1),B在(n,m)。现在A想要拜访B,由于她只想去B的家,所以每次她只会走(i,j+1)或(i+1,j)这样的路线,在草地上有k个蘑菇种在格子里(多个蘑菇可能在同一方格),问:A如果每一步随机选择的话(若她在边界上,则只有一种选择),那么她不碰到蘑菇走到B的家的概率是多少?

    第二种方法:首先分析题意,可用概率的方法来计算,做了好几道百度的题目,觉得大多数是再考概率论,所以首先要弄懂题意,最后做题前把公式写出来,这样编码时才能游刃有余. 本题中下面的第一种用迭代枚举的方法来 ...

  7. MySQL技术内幕InnoDB存储引擎(表&索引算法和锁)

    表 4.1.innodb存储引擎表类型 innodb表类似oracle的IOT表(索引聚集表-indexorganized table),在innodb表中每张表都会有一个主键,如果在创建表时没有显示 ...

  8. Windows+VS+SVN实现版本控制

    Subversion已经是一个热门话题,下面介绍一下Windows下Subversion和TortoiseSVN构建SVN版本控制 问题. 首先看一些基础知识: Subversion是架设一个SVN ...

  9. C#判断WebService接口是否可用

    using MSXML2; public bool InterfaceEnble() { string url = "http://localhost:81/WebServiceLogin. ...

  10. Python中urllib2总结

    使用Python访问网页主要有三种方式: urllib, urllib2, httpliburllib比较简单,功能相对也比较弱,httplib简单强大,但好像不支持session1. 最简单的页面访 ...