hdu4318 最短路变形
和hdu有一题差不多。给的是损失比,1-c%就是保存了多少,找出最大的保存率即可。
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<queue>
using namespace std;
#define inf 99999999
#define maxn 50010
#define maxm maxn*51
int n,e,head[maxn],pre[maxm],nex[maxm];
double cost[maxm],dis[maxn];
bool vis[maxn];
queue<int> q;
void add(int u,int v,double c)
{
pre[e]=v;
nex[e]=head[u];
cost[e]=c;
head[u]=e++;
}
double spfa(int st,int end)
{
memset(dis,,sizeof(dis));
dis[st]=;
q.push(st);
while(!q.empty())
{
int u=q.front();
vis[u]=;
q.pop();
for(int i=head[u];i!=-;i=nex[i])
if(dis[pre[i]]<dis[u]*(-cost[i]))
{
dis[pre[i]]=dis[u]*(-cost[i]);
if(!vis[pre[i]])
{
q.push(pre[i]);
vis[pre[i]]=;
}
}
}
return dis[end];
}
int main()
{
while(scanf("%d",&n)!=EOF)
{
e=;
memset(head,-,sizeof(head));
for(int i=;i<=n;i++)
{
int m;
scanf("%d",&m);
for(int j=;j<m;j++)
{
int u,c;
scanf("%d%d",&u,&c);
add(i,u,c*1.0/);
}
}
int st,end,tot;
scanf("%d%d%d",&st,&end,&tot);
double px=spfa(st,end);
if(px==)
printf("IMPOSSIBLE!\n");
else
printf("%.2f\n",(-px)*tot); }
return ;
}
hdu4318 最短路变形的更多相关文章
- POJ-2253.Frogger.(求每条路径中最大值的最小值,最短路变形)
做到了这个题,感觉网上的博客是真的水,只有kuangbin大神一句话就点醒了我,所以我写这篇博客是为了让最短路的入门者尽快脱坑...... 本题思路:本题是最短路的变形,要求出最短路中的最大跳跃距离, ...
- POJ 3635 - Full Tank? - [最短路变形][手写二叉堆优化Dijkstra][配对堆优化Dijkstra]
题目链接:http://poj.org/problem?id=3635 题意题解等均参考:POJ 3635 - Full Tank? - [最短路变形][优先队列优化Dijkstra]. 一些口胡: ...
- POJ 3635 - Full Tank? - [最短路变形][优先队列优化Dijkstra]
题目链接:http://poj.org/problem?id=3635 Description After going through the receipts from your car trip ...
- POJ-1797Heavy Transportation,最短路变形,用dijkstra稍加修改就可以了;
Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K Description Background Hugo ...
- HDOJ find the safest road 1596【最短路变形】
find the safest road Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- HN0I2000最优乘车 (最短路变形)
HN0I2000最优乘车 (最短路变形) 版权声明:本篇随笔版权归作者YJSheep(www.cnblogs.com/yangyaojia)所有,转载请保留原地址! [试题]为了简化城市公共汽车收费系 ...
- 天梯杯 PAT L2-001. 紧急救援 最短路变形
作为一个城市的应急救援队伍的负责人,你有一张特殊的全国地图.在地图上显示有多个分散的城市和一些连接城市的快速道路.每个城市的救援队数量和每一条连接两个城市的快速道路长度都标在地图上.当其他城市有紧急求 ...
- Heavy Transportation POJ 1797 最短路变形
Heavy Transportation POJ 1797 最短路变形 题意 原题链接 题意大体就是说在一个地图上,有n个城市,编号从1 2 3 ... n,m条路,每条路都有相应的承重能力,然后让你 ...
- POJ 2253 Frogger ( 最短路变形 || 最小生成树 )
题意 : 给出二维平面上 N 个点,前两个点为起点和终点,问你从起点到终点的所有路径中拥有最短两点间距是多少. 分析 : ① 考虑最小生成树中 Kruskal 算法,在建树的过程中贪心的从最小的边一个 ...
随机推荐
- Spring.之.报错:Caused by: java.lang.IllegalArgumentException: No Spring Session store is configured: set the 'spring.session.store-type' property
Spring.之.报错 No Spring Session store is configured springboot在启动的时候报如下错误: Error starting ApplicationC ...
- KOA 学习(七) 路由koa-router
一.基本用法 var app = require('koa')(); var router = require('koa-router')(); router.get('/', function *( ...
- 你真的会用Action的模型绑定吗?
在QQ群或者一些程序的交流平台,经常会有人问:我怎么传一个数组在Action中接收.我传的数组为什么Action的model中接收不到.或者我在ajax的data中设置了一些数组,为什么后台还是接收不 ...
- T2485 汉诺塔升级版(普及)(递归)
https://www.luogu.org/problem/show?pid=T2485 题目背景 汉诺塔升级了 题目描述 现在我们有N个圆盘和N个柱子,每个圆盘大小都不一样,大的圆盘不能放在小的圆盘 ...
- Nonsense Time
Nonsense Time 时间限制: 10 Sec 内存限制: 128 MB 题目描述 You a given a permutation p1,p2,…,pn of size n. Initia ...
- redis订阅自动退出
1.打开报错, error_reporting(E_ALL);ini_set('display_errors', '1'); 2.没有报错,不是php最大执行时间问题,原因是socket超时3.有设置 ...
- c#还有一点不太明白,既然开启了线程为何还要委托呢?
2013-07-15 09:33threadroc | 浏览 1611 次 既然开启了线程为何还要委托呢?,开启线程本身不就是委托吗?为何委托要显示声明呢?Thread thread = new Th ...
- solr高亮及摘要
修改了原文的一点内容:原文地址为:http://www.cnblogs.com/rainbowzc/p/3680343.html 高亮显示 两种方法: 1.在程序里通过设置query返回高亮信息 pu ...
- shell linux基本命令实例、笔记
1. 在当前文件夹下.查找20分钟内,被訪问过的文件, 并将文件的详情显示出来: find ./ -name '*.log' -mmin -20 -exec ls -l {} \; 当然,须要指出 ...
- perfcurve.m
function [X,Y,T,auc,optrocpt,subY,subYnames] = ... perfcurve(labels,scores,posClass,varargin) %PERFC ...