http://www.lightoj.com/volume_showproblem.php?problem=1321
题意:每条边都有概率无法经过,但可以重新尝试,现给出成功率,传输次数和传输时间,求到达终点消耗时间最小的期望值的两倍。
思路:搞清楚题意后,就是个水题,暴力floyd求一下最大概率,再求下期望就好了。
/** @Date : 2016-12-02-16.24 * @Author : Lweleth (SoungEarlf@gmail.com) * @Link : https://github.com/ * @Version : */ #include <stdio.h> #include <iostream> #include <string.h> #include <algorithm> #include <utility> #include <vector> #include <map> #include <set> #include <string> #include <stack> #include <queue> //#include<bits/stdc++.h> #define LL long long #define PII pair<int ,int> #define MP(x, y) make_pair((x),(y)) #define fi first #define se second #define PB(x) push_back((x)) #define MMG(x) memset((x), -1,sizeof(x)) #define MMF(x) memset((x),0,sizeof(x)) #define MMI(x) memset((x), INF, sizeof(x)) using namespace std; const int INF = 0x3f3f3f3f; const int N = 1e5+2000; double mp[110][110]; void floyd(int n) { for(int k = 0; k < n; k++) for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { if(i == j || k == i || k == j)//注意判条件 continue; mp[i][j] = max(mp[i][j], mp[i][k]*mp[k][j]); mp[j][i] = mp[i][j]; } } } int main() { int T; int cnt = 0; cin >> T; while(T--) { int n, m; double s, k; scanf("%d%d%lf%lf", &n, &m, &s, &k); MMF(mp); while(m--) { int v, u; double p; scanf("%d%d%lf", &v, &u, &p); mp[v][u] = mp[u][v] = p / (double)100; } floyd(n); double ans = s * k * 2 / mp[0][n - 1]; printf("Case %d: %.10lf ", ++cnt, ans); } return 0; }