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 ...
随机推荐
- 使用PLC作为payload/shellcode分发系统
这个周末,我一直在鼓捣Modbus,并利用汇编语言开发了一个stager,它可以从PLC的保持寄存器中下载payload.由于有大量的PLC都暴露在互联网上,我情不自禁地想到,是否可以利用它们提供的处 ...
- Seafile 网络磁盘
Seafile 个人 网盘 1.安装 Seafile 1.安装依赖环境 使用 yum 安装 Python 及 MySQL: yum install python python-setuptools p ...
- 矩阵NumPy
常量: np.pi π 创建矩阵数组 import numpy as np # array=np.array([[1,2,3],[5,6,7]]) #定义一个2行3列的矩阵数组.2行=2维 # pri ...
- sqlalchemy-查询
User这个类创建的表 User1这个类创建的表 基本查询结果 # 1 查看sql原生语句 rs =session.query(User).filter(User.username=='budon ...
- oracle存储过程,sql语句执行时间
create or replace procedure sum_info is i integer; temp1 varchar2(50); temp2 varchar2(50); t1 date; ...
- DockerFile解析
⒈是什么? DockerFile是用来构建Docker镜像的构建文件,是由一系列命令和参数构成的脚本文件. ⒉步骤 ①手动编写一个符合规范的DockerFile文件(编写) ②使用docker bui ...
- [转]UART通信简介
1.前言 UART通信,即通用异步收发传输器(Universal Asynchronous Receiver/Transmitter). 串行通信是指利用一条传输线将资料一位位地顺序传送.特点是通信线 ...
- mac 报错Root chmod operation not permitted on file
系统:mac os 10.14.1 重启电脑 mac用户在升级系统之后,电脑启用了SIP(System Integrity Protection),增加了rootless机制,导致即使在root权限下 ...
- 对WinMain程序入口函数返回值为msg.wParam的几点理解
原文地址:http://blog.csdn.net/setflvet/article/details/6983224 1.在WinMain主函数中,最后的返回值是msg.wParam,这个参数是传递给 ...
- tomcat端口冲突,多个tomcat同时启动问题
一台PC机上安装了两个tomcat,需要同时启动,每个tomcat上跑一个程序,但是现在提示端口号冲突,需要手动更改. 需要修改/conf/server.xml四个地方: 1.<Server p ...