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 ...
随机推荐
- 2017.2.7 开涛shiro教程-第六章-Realm及相关对象(一)
原博客地址:http://jinnianshilongnian.iteye.com/blog/2018398 根据下载的pdf学习. 第六章 Realm及相关对象 1.用户.角色.权限的关系 用户和角 ...
- 几种Tab的实现方法
转载请注明出处,谢谢! 学了这久Android,今天来总结一下几种Tab的实现方法 实现方法一: ViewPage来实现 首先创建一个top.xml布局和一个bottom.xml布局,然后在主界面中通 ...
- x86 Android游戏开发专题篇之使用google breakpad捕捉c++崩溃(以cocos2dx为例)
近期一直都在x86设备上进行游戏开发.就c++层和Android java层倒没有什么要特别注意的(除了须要注意一下改动Application.mk指定平台外),在c++崩溃的时候,非常多时候看不到堆 ...
- kohana nginx的配置
kohana nginx的配置 location / { if (!-e $request_filename) { rewrite ^/(.*)$ /index.php? kohana_uri=/$1 ...
- php猴子吃桃
<?php header("content-type:text/html;charset=utf-8"); /* 有一堆桃子,猴子第一天吃了其中的一半,并再多吃了一个! 以后 ...
- 转:十六进制颜色与RGB颜色对照表
http://www.vis.cc/html/ppyj/zscs/1090.html 十六进制颜色查询 颜 色 英文代码 形象描述 十六进制 RGB LightPink 浅粉红 #FFB6C1 255 ...
- gitlab服务器邮箱配置
如想用 SMTP 代替 Sendmail 发送email,添加如下相应邮箱服务商的配置到/etc/gitlab/gitlab.rb, 然后运行gitlab-ctl reconfigure使修改生效. ...
- linux链接外网手动设置
/etc/sysconfig/network-scripts/ifcfg-eth0 设置IP网关等参数 DEVICE=eth0HWADDR=00:0C:29:C5:43:34TYPE=Etherne ...
- SQL Server 的collate的含义
什么叫排序规则呢?MS是这样描述的:"在 Microsoft SQL Server 2000 中,字符串的物理存储由排序规则控制.排序规则指定表示每个字符的位模式以及存储和比较字符所使用的规 ...
- gitHub静态页面托管
github已经是众所周知的程序员同性交友网站了,我就不多说了,(+_+)? 下面讲一讲如何在不用自己购买空间域名备案的情况下,通过github来托管自己的一些小demo或者项目 让其能够通过gith ...