0
点赞
收藏
分享

微信扫一扫

nyoj1274 信道安全(河南省第九届acm程序设计大赛)


  • 题目1274
  • ​​题目信息​​
  • ​​运行结果​​
  • ​​本题排行​​
  • ​​讨论区​​

信道安全


1000 ms  |  内存限制: 65535


描述

Alpha 机构有自己的一套网络系统进行信息传送。情报员 A 位于节点 1,他准备将一份情报 发送给位于节点 n 的情报部门。可是由于最近国际纷争,战事不断,很多信道都有可能被遭到监 视或破坏。 经过测试分析,Alpha 情报系统获得了网络中每段信道安全可靠性的概率,情报员 A 决定选 择一条安全性最高,即概率最大的信道路径进行发送情报。 你能帮情报员 A 找到这条信道路径吗? 


第一行: T 表示以下有 T 组测试数据 ( 1≤T ≤8 )

对每组测试数据:


第一行:n m 分别表示网络中的节点数和信道数 (1<=n<=10000,1<=m<=50000)


接下来有 m 行, 每行包含三个整数 i,j,p,表示节点 i 与节点 j 之间有一条信道,其信


道安全可靠性的概率为 p%。 ( 1<=i, j<=n 1<=p<=100)

输出 每组测试数据,输出占一行,一个实数 即情报传送到达节点 n 的最高概率,精确到小数点后

6 位。

样例输入

1
5 7
5 2 100
3 5 80
2 3 70
2 1 50
3 4 90
4 1 85
3 1 70

样例输出

61.200000

来源 ​​河南省第九届省赛​​

上传者 ​​onlinejudge​​



很简单的一道最短路径题。

#include <stdio.h>
#include <vector>
#include <string.h>
#include <algorithm>
#include <queue>
using namespace std;
struct node
{
int pos;
double cost;
friend bool operator<(node a,node b)
{
return a.cost<b.cost;
}
};
vector<node>link[10005];
int n;
double bfs()
{
priority_queue<node>s;
bool vis[10005];
memset(vis,false,sizeof(vis));
while(!s.empty()) s.pop();
node node1;
node1.pos=1;node1.cost=1;
s.push(node1);
while(!s.empty())
{
node1=s.top();s.pop();
if(vis[node1.pos]) continue;
vis[node1.pos]=true;
if(node1.pos==n) return node1.cost;
for(int i=0;i<link[node1.pos].size();i++)
{
node y=link[node1.pos][i];
if(!vis[y.pos])
{
y.cost=node1.cost*y.cost/100;
s.push(y);
}
}
}
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int m;
scanf("%d %d",&n,&m);
memset(link,0,sizeof(link));
for(int k=0;k<m;k++)
{
int i,j;
double p;
node temp;
scanf("%d %d %lf",&i,&j,&p);
temp.pos=j;temp.cost=p;
link[i].push_back(temp);
temp.pos=i;
link[j].push_back(temp);
}
printf("%.6lf\n",bfs()*100);
}
return 0;
}



举报

相关推荐

0 条评论