LightOj_1321 Sending Packets
题意:
给一个数据大小为S的数据包, 每一次发送需要K秒(单向),现在要从节点0 发送到节点 n-1。
其中有n - 1条路径, 每条路径都有一个传输成功率。
问传输成功所需最小时间的期望。
思路:
最小时间的期望, 即最大的传输成功率, 最小的传输次数, 即只传输成功一次所需要的时间的期望。
利用dijkstra or 中途相遇法进行求解从节点0到节点n-1的最大成功率。
设其为p。
我们所要求的是传输成功一次需要的次数的期望, 这满足几何分布, so, E = 1 / p。
所以,ans = E * 2 * K * S
代码:
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <string>
#include <vector>
#include <fstream>
#include <iterator>
#include <iostream>
#include <algorithm>
using namespace std;
#define LL long long
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define eps 1e-6
#define MAXN 110
#define MAXM 100
#define dd cout<<"debug"<<endl
#define pa {system("pause");}
#define p(x) printf("%d\n", x)
#define pd(x) printf("%.7lf\n", x)
#define k(x) printf("Case %d: ", ++x)
#define s(x) scanf("%d", &x)
#define sd(x) scanf("%lf", &x)
#define mes(x, d) memset(x, d, sizeof(x))
#define do(i, x) for(i = 0; i < x; i ++)
#define dod(i, x, l) for(i = x; i >= l; i --)
#define doe(i, x) for(i = 1; i <= x; i ++)
int n, m, s, k;
int kcase = ;
double f[MAXN][MAXN];
void solve()
{
for(int i = ; i < n; i ++)
f[i][i] = 1.0;
for(int t = ; t < n; t ++)
for(int i = ; i < n; i ++)
for(int j = ; j < n; j ++)
f[i][j] = max(f[i][j], f[i][t] * f[t][j]);
double ans = f[][n-];
double ex = (1.0 / ans) * (2.0 * k * s);
printf("Case %d: %.7lf\n", ++ kcase, ex);
} int main()
{
int T;
scanf("%d", &T);
while(T --)
{
scanf("%d %d %d %d", &n, &m, &s, &k);
int u, v, p;
for(int i = ; i < n; i ++)
for(int j = ; j < n; j ++)
f[i][j] = 0.0;
for(int i = ; i < m; i ++)
{
scanf("%d %d %d", &u, &v, &p);
f[u][v] = f[v][u] = p / 100.0;
}
solve();
}
return ;
}
LightOj_1321 Sending Packets的更多相关文章
- LightOJ - 1321 Sending Packets —— 概率期望
题目链接:https://vjudge.net/problem/LightOJ-1321 1321 - Sending Packets PDF (English) Statistics Foru ...
- LightOJ 1321 - Sending Packets 简单最短路+期望
http://www.lightoj.com/volume_showproblem.php?problem=1321 题意:每条边都有概率无法经过,但可以重新尝试,现给出成功率,传输次数和传输时间,求 ...
- Sending Packets LightOJ - 1321 (期望计算)
题面: Alice and Bob are trying to communicate through the internet. Just assume that there are N route ...
- 给libpcap增加一个新的捕包方法
libpcap是一个网络数据包捕获函数库,功能非常强大,提供了系统独立的用户级别网络数据包捕获接口,Libpcap可以在绝大多数类unix 平台下工作.大多数网络监控软件都以它为基础,著名的tcpdu ...
- Overview and Evaluation of Bluetooth Low Energy: An Emerging Low-Power Wireless Technology
转自:http://www.mdpi.com/1424-8220/12/9/11734/htm Sensors 2012, 12(9), 11734-11753; doi:10.3390/s12091 ...
- Linux中的TUN/TAP设备
今天才发现这家伙...怎么讲...深以为耻.晚上的任务是加深对它的了解,就这么定了. 1. General questions.1.1 What is the TUN ? The TUN is Vi ...
- Nmap备忘单:从探索到漏洞利用(Part 2)
这是我们的第二期NMAP备忘单(第一期在此).基本上,我们将讨论一些高级NMAP扫描的技术,我们将进行一个中间人攻击(MITM).现在,游戏开始了. TCP SYN扫描 SYN扫描是默认的且最流行的扫 ...
- TCP keepalive overview
2. TCP keepalive overview In order to understand what TCP keepalive (which we will just call keepali ...
- 网络与RPC
网络与RPC 标签 : Java基础 Java为网络编程提供的java.net包封装了底层通信细节, 包含了大量的基础组件以及TCP/UDP协议的编程接口, 使得开发者可以专注于解决问题, 而不用关注 ...
随机推荐
- 高质量CSS编写规范
①id和class的命名在保持语义性的同时尽可能的短.不推荐的写法:#navigation {} .atr {}推荐的写法 : #nav {} .author {}可以缩写单词,但缩写后务必能让人明 ...
- OC最实用的runtime总结,面试、工作你看我就足够了!
前言 runtime的资料网上有很多了,部分有些晦涩难懂,我通过自己的学习方法总结一遍,主要讲一些常用的方法功能,以实用为主,我觉得用到印象才是最深刻的,并且最后两个demo也是MJExtension ...
- Android开发之从网络URL上下载JSON数据
网络下载拉取数据中,json数据是一种格式化的xml数据,非常轻量方便,效率高,体验好等优点,下面就android中如何从给定的url下载json数据给予解析: 主要使用http请求方法,并用到Htt ...
- 编译LFS
成功编译并运行linux from scratch 7.7 system,有必要作下总结.本次用的编译LFS的环境是: 虚拟机是virtalbox宿主系统为CentOS 7.0 x86_64 (cor ...
- Spring MVC中如何传递对象参数
springController: @Controller @RequestMapping("/user") public UserController extends BaseC ...
- C#汉字转拼音首字母
输入汉字,提取其首字母: /// <summary> /// 汉字转拼音缩写 /// Code By /// 2004-11-30 /// </summary> /// < ...
- php安全模式
http://www.cnblogs.com/samson/archive/2011/08/08/2130550.html php安全模式:safe_mode=on|off启用safe_mode指令将 ...
- Solr使用初探——SolrJ的使用
二.SolrJ的使用 SolrJ覆盖了solr的全部功能,下面将自己在实际开发中所使用的程序粘贴出来并适当加以解释,由于本人比较菜,代码书写不是那么的精练,还请见谅. 1. 创建solrserver ...
- 基于mod_proxy+Apache 2.2.16+Tomcat 7的负载均衡与集群配置
第一章. 背景简介 对于大多数企业应用,都希望能做到7*24小时不间断运行.要保持如此高的可用性并非易事,比较常见的做法是将系统部署到多台机器上,每台机器都对外提供同样的功能,这就是集群.系统变为集群 ...
- linux命令打开程序
evince 打开pdf firefox 打开浏览器