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

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. weblogic11g 修改密码和重置密码【原】

    修改密码 知道密码的情况下,可参考该链接 http://www.cnblogs.com/may12138/p/6022946.html 或 http://www.cnblogs.com/lsdb/p/ ...

  2. Linux 命令详解(五)cp 命令两个高效的用法

    cp 命令两个高效的用法http://mp.weixin.qq.com/s/j7h-MayR0kCxfufWx0FtrA

  3. webkitAnimationEnd事件与webkitTransitionEnd事件

    写一个焦点图demo,css3动画完成以后要把它隐藏掉,这里会用到css3的事件,以前没有接触过,结果查了一下发现这是一片新天地啊,而且里面还有好多坑,比如重复动画多次触发什么的.anyway,我还是 ...

  4. cpu load过高问题排查

    load average的概念 top命令中load average显示的是最近1分钟.5分钟和15分钟的系统平均负载. 系统平均负载被定义为在特定时间间隔内运行队列中(在CPU上运行或者等待运行多少 ...

  5. IDEA不生成WAR包,报错

    com.intellij.javaee.oss.admin.jmx.JmxAdminException: com.intellij.execution.ExecutionExceptionProjec ...

  6. readn.c

    #include <errno.h> #include <unistd.h> ssize_t readn(int fd, void *vptr, size_t n) { siz ...

  7. luogu P3243 [HNOI2015]菜肴制作

    这题一看就知道和拓扑序有关 考虑拓扑排序的时候每次取队列里最小的数进行排序 然后就\(\mathcal{GG}\)了,因为这样只能使字典序最小,而并不能保证题目中要求的每个编号的数要在满足前面数尽量在 ...

  8. java 多线程三

    java 多线程一 java 多线程二 java 多线程三 java 多线程四 注意到 java 多线程一 中 MyThread2 运行结果出现0.-1,那是因为在操作共享数据时没有加锁导致. 加锁的 ...

  9. usbserials

    Rerference: http://blog.csdn.net/qwert12131990/article/details/52403034?locationNum=9

  10. 边沿检测方法-FPGA入门教程

    本节实验主要讲解FPGA开发中边沿检测方法,我们在设计中会经常用到.这个地方大家一定要理解. 1.1.1.原理介绍 学习HDL语言设计与其他语言不一样,HDL语言设计需要考虑更多的信号的电气特性,时序 ...