题面:

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.

题意:

Alice要通过一个路由器网络发送\(s\)个报文,发送一个报文的时间是\(2*k\),发送一个报文后,收到确定报文后才会发送下一个。发送时的成功几率并非100%,求最后发送完所有报文的期望。

思路:

对于一个路径来说,成功的几率是固定的。

所以将几率用最短路求出即可。

发送第\(x\)个报文成功的期望为:

\[E_x = p*E_{x-1}+(1-p)*E_x+2*k
\]

移项可得:

\[E_x =\frac{2*s*k}{p}
\]

#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime> #define fuck(x) cerr<<#x<<" = "<<x<<endl;
#define debug(a, x) cerr<<#a<<"["<<x<<"] = "<<a[x]<<endl;
#define lson l,mid,ls
#define rson mid+1,r,rs
#define ls (rt<<1)
#define rs ((rt<<1)+1)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int loveisblue = 486;
const int maxn = 100086;
const int maxm = 100086;
const int inf = 0x3f3f3f3f;
const ll Inf = 999999999999999999;
const int mod = 1000000007;
const double eps = 1e-6;
const double pi = acos(-1); int Head[maxm],cnt;
struct edge{
int Next,v;
double w;
}e[maxm];
struct node{
int u;
double dis;
bool operator<(const node &a)const{
return a.dis>dis;
}
};
double dis[maxn];
bool vis[maxn];
void init(){
memset(Head,-1,sizeof(Head));
memset(dis,0,sizeof(dis));
memset(vis,0,sizeof(vis));
cnt=0;
}
void add_edge(int u,int v,double w){
e[cnt].Next=Head[u];
e[cnt].v=v;
e[cnt].w=w;
Head[u]=cnt++;
}
void Dijkstra(int s){
priority_queue<node>q;
q.push(node{s,0});
dis[s]=1;
while(!q.empty()){
node exa=q.top();q.pop();
int u=exa.u;
if(vis[u]){continue;}
vis[u]=true;
for(int k=Head[u];k!=-1;k=e[k].Next){
if(!vis[e[k].v]&&dis[e[k].v]<dis[u]*e[k].w){
dis[e[k].v]=dis[u]*e[k].w;
q.push(node{e[k].v,dis[e[k].v]});
}
}
}
} int main() {
ios::sync_with_stdio(true);
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif int T;
scanf("%d",&T);
int cas = 0;
while(T--){
init();
ll n,m,s,k;
scanf("%lld%lld%lld%lld",&n,&m,&s,&k); for(int i=1;i<=m;i++){
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
add_edge(x,y,1.0*z/100);
add_edge(y,x,1.0*z/100);
}
Dijkstra(0);
double p = dis[n-1];
double ans = 2.0*s*k/p;
printf("Case %d: %f\n",++cas,ans);
} return 0;
}

Sending Packets LightOJ - 1321 (期望计算)的更多相关文章

  1. LightOJ - 1321 Sending Packets —— 概率期望

    题目链接:https://vjudge.net/problem/LightOJ-1321 1321 - Sending Packets    PDF (English) Statistics Foru ...

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

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

  3. LightOJ 1030 Discovering Gold 数学期望计算

    题目大意:给出长度为n的一条隧道,每个位置都有一定数量的财宝.给你一枚骰子,roll到几点就前进几步,如果即将到达的地方超过了这条隧道长度,就重新roll一次,走到n点结束.求这个过程能收获多少财宝. ...

  4. lightOJ 1030(期望)

    题意:有一个迷宫是1×n的格子,一个人每到一个格子就能够把这个格子内的金子所有拿走,刚開始站在第1个格子,然后開始掷骰子得到点数x,他就要从当前位置走到加x的位置.假设发现位置是大于n的就又一次掷骰子 ...

  5. LightOj_1321 Sending Packets

    题目链接 题意: 给一个数据大小为S的数据包, 每一次发送需要K秒(单向),现在要从节点0 发送到节点 n-1. 其中有n - 1条路径, 每条路径都有一个传输成功率. 问传输成功所需最小时间的期望. ...

  6. LightOJ - 1030 期望+dp

    题目链接:https://vjudge.net/problem/25907/origin 一个山洞,里面有有1到n个位置,每个位置都有一定的金币,你有一个六面的骰子,一开始你在1,每次摇到了哪个数就往 ...

  7. LightOJ - 1248 期望

    题意:有一个n面筛子,每次扔一下,每面概率相同,要求扔出n面的期望次数 题解:和第三篇论文里的例题一样,算从第i个到第i+1个的概率是(n-i)/n,n面中找n-i个没有扔到过的,期望是n/(n-i) ...

  8. CodeForces 621C 数学概率期望计算

    昨天训练赛的题..比划了好久才想出来什么意思 之前想的是暴力for循环求出来然后储存数组 后来又想了想 自己萌的可以.. 思路就是求出来每个人与他的右边的人在一起能拿钱的概率(V(或)的关系)然后*2 ...

  9. KUANGBIN带你飞

    KUANGBIN带你飞 全专题整理 https://www.cnblogs.com/slzk/articles/7402292.html 专题一 简单搜索 POJ 1321 棋盘问题    //201 ...

随机推荐

  1. python 临时修改模块搜索路径

  2. SWF在线绘本批量制作高质量PDF的新方法(重点在批量制作)

    SWF在线绘本批量制作高质量PDF的新方法(重点在批量制作) 2012-12-21  未来决定...       http://www.ebama.net/thread-107643-1-1.html ...

  3. List容器-LinkedList链表

    LinkedList--链表 特点: 删除,增加 用LinkedList性能高  层次查找不适合       查询用ArrayList  数组下标查找  插入和删除慢缺点是要做移位操作 总结:Link ...

  4. Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第十二章:几何着色器(The Geometry Shader)

    原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第十二章:几何着色器(The Geometry Shader) 代码工 ...

  5. css技巧——垂直居中

    1.父元素确定的单行垂直居中 通过设置父元素的 height 和 line-height 高度一致来实现的. 2.父元素确定的多行垂直居中 父元素高度确定的多行文本.图片.块状元素的竖直居中的方法有两 ...

  6. python if elif else 区别

    if data_ori=='医疗': # 医疗 df = pd.read_excel(path_apply + 'apply/YS_ZY_HZSQ_样例.xls', encoding='gbk', e ...

  7. VSCode 设置 CPP 代码风格

    VSCode 设置 CPP 代码风格 按 Ctrl+, 打开设置,输入 format 找到. { BasedOnStyle: Google, IndentWidth: 4 }

  8. LeetCode69 Sqrt(x)

    题意: Implement int sqrt(int x). Compute and return the square root of x.(Medium) 分析: 二分搜索套路题,不能开方开尽的时 ...

  9. 5-2 正则表达式及其re模块

    一 正则表达式 在线测试工具 http://tool.chinaz.com/regex/ 字符 量词 贪婪匹配 贪婪匹配:在满足匹配时,匹配尽可能长的字符串,默认情况下,采用贪婪匹配,<.*&g ...

  10. LOJ6079「2017 山东一轮集训 Day7」养猫

    养ImmortalCO k可重区间问题 的增强版:有上下界! 直接都选择s[i],然后再把一些调整到e[i] 考虑通过最大流的“最大”,使得至少每k个有me个e, 通过最大流的“上界”,限制每k个最多 ...