LightOJ - 1321 Sending Packets —— 概率期望
题目链接:https://vjudge.net/problem/LightOJ-1321
| 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.
- If it gets the acknowledgement of the current data in this interval
- i. If S KB of data are sent, then step 4 is followed.
- ii. Otherwise, it takes 1 KB of the next data, and then step 2 is followed.
- 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 —— 概率期望的更多相关文章
- LightOJ 1321 - Sending Packets 简单最短路+期望
http://www.lightoj.com/volume_showproblem.php?problem=1321 题意:每条边都有概率无法经过,但可以重新尝试,现给出成功率,传输次数和传输时间,求 ...
- LightOJ 1030 Discovering Gold (概率/期望DP)
题目链接:LightOJ - 1030 Description You are in a cave, a long cave! The cave can be represented by a \(1 ...
- kuangbin 带你飞 概率期望
正推不行就逆推! 经典问题:生日悖论 换成其互斥事件:m个人, 每个人生日都不相同的概率 ≤ 0.5 时最小人数. 这就是邮票收集问题的变形:每个邮票至少出现一次的概率 小于等于 0.5 邮票收集问题 ...
- 【BZOJ-1419】Red is good 概率期望DP
1419: Red is good Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 660 Solved: 257[Submit][Status][Di ...
- uvalive 7331 Hovering Hornet 半平面交+概率期望
题意:一个骰子在一个人正方形内,蜜蜂在任意一个位置可以出现,问看到点数的期望. 思路:半平面交+概率期望 #include<cstdio> #include<cstring> ...
- OI队内测试一【数论概率期望】
版权声明:未经本人允许,擅自转载,一旦发现将严肃处理,情节严重者,将追究法律责任! 序:代码部分待更[因为在家写博客,代码保存在机房] 测试分数:110 本应分数:160 改完分数:200 T1: 题 ...
- 2016 多校联赛7 Balls and Boxes(概率期望)
Mr. Chopsticks is interested in random phenomena, and he conducts an experiment to study randomness. ...
- 牛客网多校赛第9场 E-Music Game【概率期望】【逆元】
链接:https://www.nowcoder.com/acm/contest/147/E 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524 ...
- 【bzoj4832】[Lydsy2017年4月月赛]抵制克苏恩 概率期望dp
题目描述 你分别有a.b.c个血量为1.2.3的奴隶主,假设英雄血量无限,问:如果对面下出一个K点攻击力的克苏恩,你的英雄期望会受到到多少伤害. 输入 输入包含多局游戏. 第一行包含一个整数 T (T ...
随机推荐
- tomcat启动项目,起不起来
右键tomcat 选择publish
- CocoaAsyncSocket使用笔记
先去github的站点下载最新的包,然后先看看介绍. 写的比較具体了 https://github.com/robbiehanson/CocoaAsyncSocket/wiki/Intro_GCDAs ...
- Win7如何解决内存不能为Read的批处理命令
将下面文件保存为"解决内存不能为Read的批处理命令.cmd"双击运行即可 for %%1 in (%WinDir%\system32\*.dll) do regsvr32.e ...
- MySQL的备份与恢复具体解释
MySQL数据备份 在mySQL里面,有逻辑备份和物理备份.逻辑备份最大长处是对于各种存储引擎,都能够使用相同的方法来备份. 而物理备份则不同.不同的存储引擎有着不同的备份方法. 逻辑备份与恢复 备份 ...
- 【SharePoint】K2 for SharePoint 安装笔记【未完工】
0.安装环境说明 0.1.软件版本 OS : Window Server 2012 标准版 SharePoint : 2013标准版 K2 : 4.6.9 0.2.环境结构 SharePoint 20 ...
- c# 访问Mysql
下载Connector/Net驱动程序,并安装. 通过MySQLConnection对象来连接数据库,连接MySQL的程序的最前面需要引用MySql.Data.MySqlClient. using M ...
- js 解析json字符串
server端返回的数据例如以下: {"list":[{"id":1,"name":"汉族"},{"id&qu ...
- Netty(五):Netty中如何序列化数据
JDK提供了ObjectOutputStream和ObjectInputStream,用于通过网络对POJO的基本数据类型和图进行序列化和反序列化.该API并不复杂,而且可以被应用于任何实现了java ...
- iOS打包(ipa包)
1.打开XCode打开project文件.选择Product,再点击Archive. 2.鼠标右键点击Shoe In Finder 3.鼠标右键选择"显示包内容" 4.鼠标左键双击 ...
- OpenSUSE 13.1上安装StrongSwan
结果: 1)iOS 7.1设备能够拨IPSec VPN到StrongSwan电脑上面来 - Connect to VPN 2)iOS 设备浏览器能够訪问StrongSwan VPN所在的内网地址服务器 ...