题目链接: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. java中String与equals,==详解

    首先,String str1="abc",这个str1所指向的是常量池中的一块内存. 如果又有,String str2="abc",那么str1和str2所指向 ...

  2. 转: scala语言的简单入门 (IBM develop)

    转: https://www.ibm.com/developerworks/cn/java/j-lo-funinscala2/

  3. Another unnamed CacheManager already exists in the same VM

    今天学习Spring 缓存机制.遇到不少问题~ 好不easy缓存的单元測试用例调试成功了,在同一项目下单元測试另外一个文件时,发生了异常: org.springframework.beans.fact ...

  4. [Redis]windows下redis的安装和启动

    官方的下载地址是: http://redis.io/download 在win64一栏中能够看到redis原本是没有windows版本号的,windows版本号是Microsoft Open Tech ...

  5. JAVA Eclipse ActivityManager Warning Activity not started, its current task has been brought to the front怎么办

    Eclipse运行提示Activity not started,因为当前程序已经在运行,需要退出当前程序再测试

  6. Git相关命令教程

    一.在GitHub上创建新项目 (1)在GitHub首页 “New repository”,创建新版本库“test” (2)在本地使用GitBash,将repository clone到本地 git ...

  7. Oracle TNS路径

    修改tnsnames.oRA,监听文件   Oracle TNS路径 G:\Oracle\product\11.2.0\client_1\network\admin\tnsnames.oRA

  8. 深入了解Struts1的执行机理

    要说Struts1的工作流程.就必需要说一下Model1和Model2了.由于这个框架是踏着他们的尸骨一步一步的发展起来的. Model1开发模式,想想我们刚刚開始接触Java的时候,我们用的就是这样 ...

  9. 笔记本中G-Sensor(加速计) M-Sensor 陀螺仪等传感器的区别

    1.G-sensor重力传感器 作用 G-sensor中文是加速度传感器的意思(英文全称是Accelerometer-sensor),它能够感知到加速力的变化,加速力就是当物体在加速过程中作用在物体上 ...

  10. Centos 7 远程桌面客户端

    在centos下面要远程连接windows,有人说用rdesktop,但是好像centos 7没有,对从源代码编译也不大感兴趣. 幸好还有人提醒, https://geekblood.com/2014 ...