poj 2472
来源:互联网 发布:sql group by distinct 编辑:程序博客网 时间:2024/05/17 21:46
题意:
给你一个无向图,然后每条边的权值就是不被抓的概率,有个货要从1逃到n,问你他的最安全概率是多少?
思路:
给你一个无向图,然后每条边的权值就是不被抓的概率,有个货要从1逃到n,问你他的最安全概率是多少?
思路:
水题,直接跑就行了,一开始自己想多了,还转换了一下log,后来发现转换之后会有正环,有正环求最长路就呵呵了,直接跑就行了,具体看代码,我写的是spfa.
#include<stdio.h>#include<math.h>#include<string.h>#include<queue>#define N_node 100 + 10#define N_edge 5500#define INF 10000000using namespace std;typedef struct{ int to ,next; double cost;}STAR;STAR E[N_edge];int list[N_node] ,tot;double s_x[N_node];void add(int a ,int b ,double c){ E[++tot].to = b; E[tot].cost = c; E[tot].next = list[a]; list[a] = tot;}void Spfa(int s ,int n){ int mark[N_node] = {0}; for(int i = 0 ;i <= n ;i ++) s_x[i] = -INF; s_x[s] = 1 ,mark[s] = 1; queue<int>q; q.push(s); while(!q.empty()) { int tou ,xin; tou = q.front(); q.pop(); mark[tou] = 0; for(int k = list[tou] ;k ;k = E[k].next) { xin = E[k].to; if(s_x[xin] < s_x[tou] * E[k].cost) { s_x[xin] = s_x[tou] * E[k].cost; if(!mark[xin]) { mark[xin] = 1; q.push(xin); } } } } return ;}int main (){ int n ,m ,a ,b ,c ,i; while(~scanf("%d" ,&n) && n) { scanf("%d" ,&m); memset(list ,0 ,sizeof(list)) ,tot = 1; for(i = 1 ;i <= m ;i ++) { scanf("%d %d %d" ,&a ,&b ,&c); add(a ,b ,c * 0.01); add(b ,a ,c * 0.01); } Spfa(1 ,n); printf("%lf percent\n" ,s_x[n] * 100); } return 0;}
0 0
- poj 2472
- poj 2472
- POJ
- poj
- POJ
- POJ
- poj
- poj
- POJ
- POJ
- poj
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- linux脚本编程---(>和>>)文件重定向
- getContextPath、getServletPath、getRequestURI的区别
- Windows下编译最新的x264 (2011-02-23 09:20:02)
- UVa 10179 - Irreducable Basic Fractions
- hdu1069——Monkey and Banana
- poj 2472
- 安装虚拟机
- 阅读SEO文章 如何分析自身网站数据
- 《程序员的思维修炼 –开发认知潜能的九堂课》读书笔记
- linux脚本编程---“|”管道pipe的使用
- 软件工程作业1——简单小学题库
- 十一学习成果
- 使用Numpy和Scipy处理图像
- jquery遍历表格,以及遍历radio,使用iCheck设置radio选中