hdu 1596 乘积的最大值
一般题是 和的最小值 这个是乘积的最大值
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 乘积的最大值的更多相关文章
- HDU.1596 find the safest road (Floyd)
HDU.1596 find the safest road (Floyd) 题意分析 与普通的最短路不太相同,本题有些许的变化. 1. 要找到由i到j最安全的路,故在求解的时候要保证mp[i][j]尽 ...
- hdu 1596(Floyd 变形)
http://acm.hdu.edu.cn/showproblem.php?pid=1596 find the safest road Time Limit: 10000/5000 MS (Java/ ...
- hdu 1596 find the safest road
http://acm.hdu.edu.cn/showproblem.php?pid=1596 #include <cstdio> #include <cstring> #inc ...
- HDU 1596 最短路变形
这道题怎么都是TLE,报警了,先放在这 http://acm.hdu.edu.cn/showproblem.php?pid=1596 #include <iostream> #includ ...
- hdu 1596 find the safest road (变形SP && dij+heap)
Problem - 1596 变形最短路问题,给出邻接矩阵,要求求出给定点对间安全率最大值. 这题可以用dijkstra+heap来做.对于每一个查询,做一次dij即可. 代码如下: #include ...
- HDU 1596 find the safest road (最短路)
find the safest road Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- hdu 1596 find the safest road (最短路径)
find the safest road Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- HDU 1596 floyd
find the safest road Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- hdu 1596 find the safest road(最短路,模版题)
题目 这是用Dijsktra做的,稍加改动就好,1000ms..好水.. #define _CRT_SECURE_NO_WARNINGS #include<string.h> #inclu ...
随机推荐
- AVL树的JAVA实现及AVL树的旋转算法
1,AVL树又称平衡二叉树,它首先是一颗二叉查找树,但在二叉查找树中,某个结点的左右子树高度之差的绝对值可能会超过1,称之为不平衡.而在平衡二叉树中,任何结点的左右子树高度之差的绝对值会小于等于 1. ...
- Prezento – 轻量、简单的 jQuery 幻灯片插件
Prezento 是一个超级简单的 jQuery 幻灯片插件.可以让你网页以新颖的交互方式呈现.另外,Prezento 支持响应式设计,配置项也很灵活,可以根据你需要的效果配置. 您可能感兴趣的相关文 ...
- aop(Aspect Oriented Programming)面向切面编程
AOP,一个oop的后传,面向切面,一个基于代理模式的机制. 举例子把:说原理很难理解, 吃饭:谁都得吃饭,一个老师类,有吃饭的方法.一个学生类,也得有吃饭的方法.是不是都得实现这个方法?构建一个pe ...
- 向GitHub上上传代码(转)
使用git将项目上传到github(最简单方法) 首先你需要一个github账号,所有还没有的话先去注册吧! https://github.com/ 我们使用git需要先安装git工具,这里给出下 ...
- js 拖拽 碰撞 + 重力 运动
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- C# HTTP上传多个文件及传递参数
1.HTTP上传文件及传递参数 #region 6.0 上传多个文件和参数 /// <summary> /// HttpUploadFile /// </summary> // ...
- KVM 部署 日常操作
KVM 安装 条件检测准备:CPU 虚拟化 ,现在物理机都支持. 开启cpu虚拟化 现在至强一般机器都有 cat /proc/cpuinfo |grep flags 需要全虚拟化支持为vmx(Inte ...
- luogu P1627 [CQOI2009]中位数
传送门 要求有多少个长度为奇数的区间满足某个数为区间中位数 这样的区间,大于中位数的数个数 等于 小于中位数的数个数 用类似于前缀和的方法,设\(X_i\)为\(i\)和数\(b\)形成的区间内,大于 ...
- freeRTOS中文实用教程4--资源管理概述
1.前言 多任务系统中存在一种潜在的风险.当一个任务在使用某个资源的过程中,即还没有完全结束对资源的访问时,便被切出运行态,使得资源处于非一致,不完整的状态 2.并发抢占导致错误的场景 (1)访问外设 ...
- ubuntu cron 及 crontab 自动执行任务
Add the below line (with tweaks) to the end of /etc/crontab: 30 23 * * * root shutdown -h now At 23: ...