一般题是 和的最小值 这个是乘积的最大值

Sample Input
3
1 0.5 0.5
0.5 1 0.4
0.5 0.4 1
3
1 2 //起点 终点
2 3
1 3

Sample Output
0.500
0.400
0.500

Dijkstra:

 # include <iostream>
# include <cstdio>
# include <cstring>
# include <algorithm>
# include <cmath>
# define LL long long
using namespace std ; const int MAXN=;
const int INF=0x3f3f3f3f;
int n ;
bool vis[MAXN];
double cost[MAXN][MAXN] ;
double lowcost[MAXN] ;
void Dijkstra(int beg)
{
for(int i=;i<n;i++)
{
lowcost[i]=cost[beg][i];vis[i]=false;;
}
for(int j=;j<n;j++)
{
int k=-;
double Max= -INF;
for(int i=;i<n;i++)
if(!vis[i]&&lowcost[i] > Max)
{
Max=lowcost[i];
k=i;
}
if(k==-)
break ;
vis[k]=true;
for(int i=;i<n;i++)
lowcost[i]=max(lowcost[i],lowcost[k]*cost[k][i]) ; } } int main ()
{
// freopen("in.txt","r",stdin) ; while (scanf("%d" , &n ) !=EOF)
{
int i , j ;
for (i = ; i < n ; i++)
for (j = ; j < n ; j++)
scanf("%lf" , &cost[i][j]) ;
int m ;
scanf("%d" , &m) ;
while(m--)
{
int s , e;
scanf("%d %d" , &s , &e) ;
Dijkstra(s-) ;
if (lowcost[e-] > || lowcost[e-] <= )
printf("What a pity!\n") ;
else
printf("%.3lf\n" , lowcost[e-]) ;
}
} return ;
}

hdu 1596 乘积的最大值的更多相关文章

  1. HDU.1596 find the safest road (Floyd)

    HDU.1596 find the safest road (Floyd) 题意分析 与普通的最短路不太相同,本题有些许的变化. 1. 要找到由i到j最安全的路,故在求解的时候要保证mp[i][j]尽 ...

  2. hdu 1596(Floyd 变形)

    http://acm.hdu.edu.cn/showproblem.php?pid=1596 find the safest road Time Limit: 10000/5000 MS (Java/ ...

  3. hdu 1596 find the safest road

    http://acm.hdu.edu.cn/showproblem.php?pid=1596 #include <cstdio> #include <cstring> #inc ...

  4. HDU 1596 最短路变形

    这道题怎么都是TLE,报警了,先放在这 http://acm.hdu.edu.cn/showproblem.php?pid=1596 #include <iostream> #includ ...

  5. hdu 1596 find the safest road (变形SP && dij+heap)

    Problem - 1596 变形最短路问题,给出邻接矩阵,要求求出给定点对间安全率最大值. 这题可以用dijkstra+heap来做.对于每一个查询,做一次dij即可. 代码如下: #include ...

  6. HDU 1596 find the safest road (最短路)

    find the safest road Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  7. hdu 1596 find the safest road (最短路径)

    find the safest road Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  8. HDU 1596 floyd

    find the safest road Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  9. hdu 1596 find the safest road(最短路,模版题)

    题目 这是用Dijsktra做的,稍加改动就好,1000ms..好水.. #define _CRT_SECURE_NO_WARNINGS #include<string.h> #inclu ...

随机推荐

  1. Linux记录-普通用户下执行sudo xxx 找不到命令解决方案

    chmod 777 /etc/sudoers vim /etc/sudoers 1.可以使用 secure_path 指令修改 sudoers 中默认的 PATH为你想要的路径.这个指令指定当用户执行 ...

  2. C#星夜拾遗之delegate示例

    概念 delegate即委托.如果你使用过C++或者js中的回调函数,你会更容易明白一些.在异步操作中常常使用回调函数,例如在Ajax中,当HttpRequest执行异步请求时,就需要有一个状态改变时 ...

  3. PHP第三方登录—OAuth2.0协议

    第2章 OAuth授权流程详解 

  4. TestNg失败重试机制

    TestNg提供了失败重试接口IRetryAnalyzer,需要实现retry方法: package com.shunhe.testngprac.retry; import org.testng.IR ...

  5. 虚拟机centos7系统下安装hadoop ha和yarn ha(详细)

    一:基础环境准备 (一):虚拟机新建五个centos7系统(复制文件夹的方式) (二):角色分配 (三)按照角色分配表配置 (1)更改主机ip(自行查找),如果只是个人搭建玩一玩,可选择安装cento ...

  6. 从前端和后端两个角度分析jsonp跨域访问(完整实例)

    一.什么是跨域访问 举个栗子:在A网站中,我们希望使用Ajax来获得B网站中的特定内容.如果A网站与B网站不在同一个域中,那么就出现了跨域访问问题.你可以理解为两个域名之间不能跨过域名来发送请求或者请 ...

  7. windows安装anaconda 报错failed to create anacoda menu ?

    windows安装anaconda 报错failed to create anacoda menu ? 装了无数次,每次都是 failed to create anacoda menu然后无选择忽略, ...

  8. Linux mmc framework2:基本组件之block

    1.前言 本文主要block组件的主要流程,在介绍的过程中,将详细说明和block相关的流程,涉及到其它组件的详细流程再在相关文章中说明. 2.主要数据结构和API 2.1 struct mmc_ca ...

  9. 3D中的OBJ文件格式详解

    常见到的*.obj文件有两种:第一种是基于COFF(Common Object File Format)格式的OBJ文件(也称目标文件),这种格式用于编译应用程序:第二种是Alias|Wavefron ...

  10. 企业环境下的OpenStack自动化功能测试(转载)

    原文地址:http://mp.weixin.qq.com/s?__biz=MzAxOTAzMDEwMA==&mid=2652502581&idx=1&sn=0c26519bcb ...