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协议的编程接口, 使得开发者可以专注于解决问题, 而不用关注 ...
随机推荐
- 动作之CCActionInterval(持续动作)家族
持续动作,顾名思义,就是该动作的执行将持续一段时间.因此持续动作的静态生成函数,往往附带一个时间值Duration. 持续动作类名后缀:一般有两种后缀,一种是To,一种是By.To表示最终达到的目标值 ...
- python--class test
# !usr/bin/env python3#-*- coding:utf-8 -*- 'a test class'class Student(object): def __init__(se ...
- C#中的字符串
1. 值类型与引用类型比较 classProgram { staticvoid Main() { int b = a; //将a的副本给变量b b = 10; Console.WriteLi ...
- JUnit4简要说明
单元测试(unit testing),是指对软件中的最小可测试单元进行检查和验证. 开发者编写一小段代码,用于检验被测代码的一个很小的.很明确的功能是否正确. 通常而言,一个单元测试是用于判断某个特定 ...
- Python入门学习教程:数据库操作,连接MySql数据库
各位志同道合的同仁可以点击上方关注↑↑↑↑↑↑ 本教程致力于程序员快速掌握Python语言编程. 本文章内容是基于上次课程Python教程:Python教程:连接数据库,对数据进行增删改查操作 和py ...
- magento中的一些技巧
1.加载某个attribute: $attributeCode=Mage::getModel('catalog/resource_eav_attribute') ...
- jQuery Validation Plugin学习
http://blog.csdn.net/violet_day/article/details/14109261 jQuery Validation Plugin Demo 一.默认校验规则 (1)r ...
- 有关IT的小笑话
路上看到一个女孩朝我走来:“请问你是不是学计算机的?”我疑惑的点点头,她兴奋的又问:“那你有女朋友吗?”我兴奋的摇头:“没有啊,是不是你家电脑坏了?”她转身对后面的女孩说:“看吧,我就知道这种背双肩包 ...
- 20160410javaweb之JDBC---DBUtils框架
DBUtils 1.DbUtils 工具类 2.QueryRunner -- 两行代码搞定增删改查 (1)QueryRunner() --需要控制事务时,使用这组方法 int update(Conne ...
- 在VM虚拟机中安装centos7