題目:
鏈接:點擊打開鏈接
題意:
思路:
對dijkstra稍作修改即可,每次更新dis[]時改為乘積。
代碼:
#include---------------------------------------------------------------#include #include using namespace std; #define INF 100000000 const int N = 1010; int n,m; double map[N][N],dis[N]; int st,ed; void dijkstra() { int vis[N]; memset(vis,0,sizeof(vis)); for(int i=1; i<=n; i++) { dis[i] = map[st][i]; } for(int i=1; i 1e-6) { maxx = dis[x=y]; } } vis[x] = 1; for(int y=1; y<=n; y++) { if(maxx*map[x][y] - dis[y] > 1e-6) dis[y] = maxx*map[x][y]; } } if(dis[ed]) printf("%.3lf\n",dis[ed]); else printf("What a pity!\n"); } int main() { //freopen("input.txt","r",stdin); double s; while(scanf("%d",&n) != EOF) { for(int i=1; i<=n; i++) { for(int j=1; j<=n; j++) { scanf("%lf",&s); map[i][j] = s; } } scanf("%d",&m); for(int i=1; i<=m; i++) { scanf("%d%d",&st,&ed); dijkstra(); } } return 0; }
收獲:
---------------------------------------------------------------
戰斗,從不退縮;奮斗,永不停歇~~~~~~~~~