POJ3621 Sightseeing Cows【最短路】
题目大意:在一个无向图里找一个环,是的点权和除以边权和最大
思路:UVA11090姊妹题 事实上当这题点权和都为1时就是上一题TUT
#include <stdio.h>
#include <iostream>
#include<queue>
#include <string.h>
#include <algorithm>
#define maxn 10009
#define maxm 10001
#define esp 0.001
using namespace std;
int head[1009],next[maxn],now=0,value1[maxn];
int point[maxn],inque[1009],n,m,f[1009];
double dist[1009];
void add(int x,int y,int u,int v)
{
next[++now]=head[x];
head[x]=now;
point[now]=y;
value1[now]=u;
}
int spfa(int s,double ans)
{
memset(inque,0,sizeof(inque));
for(int i=1;i<=n+1;i++)dist[i]=0x3f3f3f3f;
dist[s]=0;
int visit[maxn]={0};
visit[s]=1;
queue<int>q;
q.push(s);
while(!q.empty())
{
int u=q.front();
q.pop();
visit[u]=0;
for(int i=head[u];i;i=next[i])
{
int k=point[i];
double vv=ans*value1[i]-f[k];;
if(dist[u]+vv<dist[k])
{
dist[k]=dist[u]+vv;
if(visit[k]==0)
{
visit[k]=1;
inque[k]++;
if(inque[k]>=n)return 1;
q.push(k);
}
}
}
}
return 0;
}
int main()
{
double l=0,r=2000;
int x,y,v;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
{
// add(n+1,i,0,0);
scanf("%d",&f[i]);
}
for(int i=1;i<=m;i++)
{
scanf("%d%d%d",&x,&y,&v);
add(x,y,v,f[y]);
// add(y,x,v,f[x]);
// r+=v;
}
while(r-l>esp)
{
double mid=(l+r)/2;
if(spfa(1,mid)==0)r=mid;else l=mid;
}
// printf("%d\n",spfa(1,6.128));
printf("%.2f\n",l);
return 0;
}
POJ3621 Sightseeing Cows【最短路】的更多相关文章
- POJ3621 Sightseeing Cows 最优比率环 二分法
题目链接:http://poj.org/problem?id=3621 Sightseeing Cows Time Limit: 1000MS Memory Limit: 65536K Total ...
- poj3621 Sightseeing Cows --- 01分数规划
典型的求最优比例环问题 參考资料: http://blog.csdn.net/hhaile/article/details/8883652 此题中,给出每一个点和每条边的权值,求一个环使 ans=∑点 ...
- POJ3621 Sightseeing Cows(最优比率环)
题目链接:id=3621">http://poj.org/problem?id=3621 在一个有向图中选一个环,使得环上的点权和除以边权和最大.求这个比值. 经典的分数规划问题,我认 ...
- poj3621 Sightseeing Cows
01分数规划 二分+spfa负环(SLF优化) #include<cstdio> #include<iostream> #include<cstring> #inc ...
- 【POJ3621】Sightseeing Cows 分数规划
[POJ3621]Sightseeing Cows 题意:在给定的一个图上寻找一个环路,使得总欢乐值(经过的点权值之和)/ 总时间(经过的边权值之和)最大. 题解:显然是分数规划,二分答案ans,将每 ...
- 【POJ3621】【洛谷2868】Sightseeing Cows(分数规划)
[POJ3621][洛谷2868]Sightseeing Cows(分数规划) 题面 Vjudge 洛谷 大意: 在有向图图中选出一个环,使得这个环的点权\(/\)边权最大 题解 分数规划 二分答案之 ...
- 【POJ3621】Sightseeing Cows
Sightseeing Cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8331 Accepted: 2791 ...
- Sightseeing Cows(最优比率环)
Sightseeing Cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8915 Accepted: 3000 ...
- POJ 3621 Sightseeing Cows 【01分数规划+spfa判正环】
题目链接:http://poj.org/problem?id=3621 Sightseeing Cows Time Limit: 1000MS Memory Limit: 65536K Total ...
随机推荐
- python_10(模块与包)
第1章 模块 1.1 模块的种类 1.2 定义 1.3 作用 1.4 导入及使用 1.4.1 import 1.4.2 测试一: 1.4.3 测试二: 1.4.4 测试三: 1.4.5 小结 1.4. ...
- zoj3772Calculate the Function(矩阵+线段树)
链接 表达式类似于斐波那契 但是多了一个变量 不能用快速幂来解 不过可以用线段树进行维护 对于每一个点够一个2*2的矩阵 1 a[i] 1 0 这个矩阵应该不陌生 类似于构造斐波那契的那个数列 ...
- [转]VC++中对文件的写入和读取
本文转自:http://blog.csdn.net/fanghb_1984/article/details/7425705 本文介绍两种方法对文件进行读取和写入操作:1.采用fstream类:2.采用 ...
- sql子查询的例子
1.单行子查询 select ename,deptno,sal from emp where deptno=(select deptno from dept ...
- Andriod 简介
Andriod系统采用分层架构,分为4层: 应用程序层(Applications) 包含所有安装在手机上的应用程序(包括系统自带的程序) 应用程序框架层(Application Framework) ...
- PHP Deprecated: Function split() is deprecated in /var/www/html/cacti/cmd.php on line 61
[root@localhost cacti]# php cmd.php PHP Deprecated: Function split() is deprecated in /var/www/html/ ...
- vue :class 可以接收 字符串 数组 和 对象 对象里面的key值 根据true或false 显示不显示
vue :class 可以接收 字符串 数组 和 对象 对象里面的key值 根据true或false 显示不显示 https://cn.vuejs.org/v2/guide/class-and-sty ...
- HTML习题附答案
第一章 1.HTML指的是( A ). A超文本标记语言(Hyper Text Markup Language) B家庭工具标记语言(Home Tool Markup Language) C超 ...
- Visual Studio 2017部署 webStrom开发的nodejs项目
vs点击文件--新建--项目--JavaScript--Node.js--通过现有Node.js代码 wxxcx为nodejs项目根目录,然后右击整个项目--属性:1.启动目录2.默认打开的链接3.设 ...
- C++类的存储及虚函数实现原理
一.C++成员函数在内存中的存储方式 用类去定义对象时,系统会为每一个对象分配存储空间.如果一个类包括了数据和函数,要分别为数据和函数的代码分配存储空间.按理说,如果用同一个类定义了10个对象,那么就 ...