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

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. mips体系堆栈回溯分析与实现

    转载:http://www.sohu.com/a/118385096_468740 mips栈帧原理 Call stack 是指存放某个程序的正在运行的函数的信息的栈.Call stack 由 sta ...

  2. MySQL - 日常操作二 备份还原

    登录mysql的命令 # 格式: mysql -h 主机地址 -u 用户名 -p 用户密码 mysql -h 110. -P3306 -uroot -p mysql -uroot -p -S /dat ...

  3. 如何成为软件测试职场“头号玩家”,月入10k+

    最近看了一部电影,叫<头号玩家>,电影挺不错的,延伸到自己的测试职业生涯,其实在我们的测试职场,也是存在头号玩家的,但并不是真的在玩,而是在努力工作. 不管是什么游戏,如果要玩通关升级,那 ...

  4. python3之Django多数据库

    1.定义数据库 在django项目中, 一个工程中存在多个APP应用很常见:有时候希望不同的APP连接不同的数据库,这个时候需要建立多个数据库连接.在Django的setting中使用DATABASE ...

  5. freeRTOS中文实用教程5--内存管理

    1.前言 不同的嵌入式系统具有不同的内存配置和时间要求.所以单一的内存分配算法只可能适合部分应用程序. FreeRTOS 将内存分配作为可移植层面(相对于基本的内核代码部分而言).这使得不同的应用程序 ...

  6. Linux文件系统3--打开文件

    1.前言 本文所述关于文件管理的系列文章主要是对陈莉君老师所讲述的文件系统管理知识讲座的整理. Linux可以支持不同的文件系统,它源于unix文件系统,也是unix文件系统的一大特色. 本文将以不同 ...

  7. Class create, device create, device create file【转】

    来自:http://www.hovercool.com/en/Class_create,_device_create,_device_create_file 开始写Linux设备驱动程序的时候,很多时 ...

  8. TCP建立流程 【转】

    解决TCP连接数过多的问题 TCP状态迁移,CLOSE_WAIT & FIN_WAIT2 的问题 TCP状态迁移 大家对netstat -a命令很熟悉,但是,你有没有注意到STATE一栏呢,基 ...

  9. oracle巡检脚本备份

    重做日志生成情况,一天生成日志大小:select round(sum(blocks*block_size)/1024/1024/1024,2) BLOCK from v\$archived_log w ...

  10. Html5 序列帧动画

    <!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/xhtml"> ...