OpenJ_Bailian3375
Farmer John has decided to reward his cows for their hard work by taking them on a tour of the big city! The cows must decide how best to spend their free time.
Fortunately, they have a detailed city map showing the L (2 ≤ L ≤ 1000) major landmarks (conveniently numbered 1.. L) and the P (2 ≤ P ≤ 5000) unidirectional cow paths that join them. Farmer John will drive the cows to a starting landmark of their choice, from which they will walk along the cow paths to a series of other landmarks, ending back at their starting landmark where Farmer John will pick them up and take them back to the farm. Because space in the city is at a premium, the cow paths are very narrow and so travel along each cow path is only allowed in one fixed direction.
While the cows may spend as much time as they like in the city, they do tend to get bored easily. Visiting each new landmark is fun, but walking between them takes time. The cows know the exact fun values Fi (1 ≤ Fi ≤ 1000) for each landmark i.
The cows also know about the cowpaths. Cowpath i connects landmark L1i to L2i (in the direction L1i -> L2i ) and requires time Ti (1 ≤ Ti ≤ 1000) to traverse.
In order to have the best possible day off, the cows want to maximize the average fun value per unit time of their trip. Of course, the landmarks are only fun the first time they are visited; the cows may pass through the landmark more than once, but they do not perceive its fun value again. Furthermore, Farmer John is making the cows visit at least two landmarks, so that they get some exercise during their day off.
Help the cows find the maximum fun value per unit time that they can achieve.
Input
* Line 1: Two space-separated integers: L and P
* Lines 2..L+1: Line i+1 contains a single one integer: Fi
* Lines L+2..L+P+1: Line L+i+1 describes cow path i with three space-separated integers: L1i , L2i , and Ti
Output
* Line 1: A single number given to two decimal places (do not perform explicit rounding), the maximum possible average fun per unit time, or 0 if the cows cannot plan any trip at all in accordance with the above rules.
Sample Input
5 7
30
10
10
5
10
1 2 3
2 3 2
3 4 5
3 5 2
4 5 5
5 1 3
5 2 2
Sample Output
6.00
【题目大意】
给出一个有向图,问求一个回路,使得回路上的点权之和/边权之和 最大。
【解题思路】
此题是对01分数规划的应用,那么首先明白01分数规划的思想,用基础分数规划,就是第三类,最优比率环裸题
spfa判正环。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
#define N 1007
#define M 5007
using namespace std; int n,m;
int num[N];double w[N],dis[N];bool vis[N];
int cnt,head[N],Next[M],rea[M];double val[M]; void Add(int u,int v,double fee)
{Next[++cnt]=head[u],head[u]=cnt,rea[cnt]=v,val[cnt]=fee;}
bool spfa(double rate)
{
for (int i=;i<=n;i++)
dis[i]=,vis[i]=,num[i]=;
queue<int>q;
for (int i=;i<=n;i++)
q.push(i);
while(!q.empty())
{
int u=q.front();q.pop();
for (int i=head[u];i!=-;i=Next[i])
{
int v=rea[i];double fee=w[u]-rate*val[i];
if (dis[u]+fee>dis[v])
{
dis[v]=dis[u]+fee;
if (!vis[v])
{
q.push(v);
num[v]++;vis[v]=;
if (num[v]>n) return true;
}
}
}
vis[u]=;
}
return false;
}
int main()
{
memset(head,-,sizeof(head));
scanf("%d%d",&n,&m);
for (int i=;i<=n;i++)
scanf("%lf",&w[i]);
int x,y;double z;
for (int i=;i<=m;i++)
{
scanf("%d%d%lf",&x,&y,&z);
Add(x,y,z);
}
double l=0.0,r=1000.0;
while (r-l>0.0001)
{
double mid=(l+r)/;
if (spfa(mid)) l=mid;
else r=mid;
}
printf("%.2f\n",l);
}
POJ过不了
OpenJ_Bailian3375的更多相关文章
随机推荐
- CNNs 在图像分割中应用简史: 从R-CNN到Mask R-CNN
作者:嫩芽33出处:http://www.cnblogs.com/nenya33/p/6756024.html 版权:本文版权归作者和博客园共有 转载:欢迎转载,但未经作者同意,必须保留此段声明:必须 ...
- 广播接收者 BroadcastReceiver
1. 分为动态注册和静态注册, 静态注册在清单文件里配置即可.动态创建为代码手动添加. 在锁屏广播中, 使用静态创建消息接受不成功, 原因未知. 动态即可. 代码如下: 2. 创建类, 继承与Broa ...
- 带二级目录的Nginx配置------目前找到的最简单的方法
由于项目不知一个,所以不得不为每一个项目建一个专有的文件夹,这就导致了在配置nginx的时候会出现二级目录 目前找到的最简单的方法 - step1:修改 vue.config.js 添加配 ...
- Vue的elementUI实现自定义主题
使用vue开发项目,用到elementUI,根据官网的写法,我们可以自定义主题来适应我们的项目要求,下面来介绍一下两种方法实现的具体步骤,(可以参考官方文档自定义主题官方文档),先说项目中没有使用sc ...
- Burpsuite1.7.03网站渗透神器最新破解版
众所周知,Burp Suite是响当当的web应用程序渗透测试集成平台.从应用程序攻击表面的最初映射和分析, 到寻找和利用安全漏洞等过程,所有工具为支持整体测试程序而无缝地在一起工作. 平台中所有工具 ...
- Dubbo服务的搭建
dubbo框架主要作用是基于RPC的远程调用服务管理,但是注册中心是用的zookeeper,搭建dubbo,首先要安装zookeeper,配置zookeeper... 实现功能如图所示:(存在2个系统 ...
- asp.net core vs2017运行控制台应用程序一闪而过没执行
在cmd中执行dotnet run,会提示当前应用程序版本高于当前安装的.net core sdk 版本 解决: 升级.net core版本到最新
- ext笔记
命名 The top-level namespaces and the actual class names should be CamelCased. Everything else shoul ...
- 组合的输出(DFS)
题目描述: 排列与组合是常用的数学方法,其中组合就是从n个元素中抽出r个元素(不分顺序且r<=n),我们可以简单地将n个元素理解为自然数1,2,…,n,从中任取r个数. 现要求你用递归的方法输出 ...
- Linux基础学习-基本命令
基本命令 date命令 参数 作用 %t 跳格 %H 小时(00-23) %I 小时(00-12) %M 分钟(00-59) %S 秒(00-59) %j 今年中的第几天 [root@qdlinux ...