[题目链接]

http://poj.org/problem?id=3621

[算法]

01分数规划(最优比率环)

[代码]

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#include <stack>
#include <limits.h>
using namespace std;
#define MAXL 1010
#define MAXP 5010
const double eps = 1e-;
const int T = 1e5;
const int INF = 2e9; struct edge
{
int to,w,nxt;
} e[MAXP]; int i,L,P,a,b,w,tot;
int f[MAXL],head[MAXL];
double l,r,mid,ans; inline void addedge(int u,int v,int w)
{
tot++;
e[tot] = (edge){v,w,head[u]};
head[u] = tot;
}
inline bool spfa(double mid)
{
int i,cur,v;
double w;
static int cnt[MAXL];
static bool inq[MAXL];
static double dist[MAXL];
queue< int > q;
memset(cnt,,sizeof(cnt));
memset(inq,false,sizeof(inq));
while (!q.empty()) q.pop();
for (i = ; i <= L; i++)
{
q.push(i);
cnt[i] = ;
inq[i] = true;
dist[i] = -INF;
}
while (!q.empty())
{
cur = q.front();
q.pop();
inq[cur] = false;
for (i = head[cur]; i; i = e[i].nxt)
{
v = e[i].to;
w = 1.0 * f[cur] - 1.0 * mid * e[i].w;
if (dist[cur] + w > dist[v])
{
dist[v] = dist[cur] + w;
if (!inq[v])
{
inq[v] = true;
cnt[v]++;
if (cnt[v] > L) return true;
q.push(v);
}
}
}
}
return false;
} int main()
{ scanf("%d%d",&L,&P);
for (i = ; i <= L; i++) scanf("%d",&f[i]);
for (i = ; i <= P; i++)
{
scanf("%d%d%d",&a,&b,&w);
addedge(a,b,w);
}
l = ; r = T;
while (r - l > eps)
{
mid = (l + r) / 2.0;
if (spfa(mid))
{
ans = mid;
l = mid;
} else r = mid;
}
printf("%.2f\n",ans); return ; }

[POJ 3621] Sightseeing Cows的更多相关文章

  1. POJ 3621 Sightseeing Cows 【01分数规划+spfa判正环】

    题目链接:http://poj.org/problem?id=3621 Sightseeing Cows Time Limit: 1000MS   Memory Limit: 65536K Total ...

  2. POJ 3621 Sightseeing Cows(最优比例环+SPFA检测)

    Sightseeing Cows Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10306   Accepted: 3519 ...

  3. POJ 3621 Sightseeing Cows | 01分数规划

    题目: http://poj.org/problem?id=3621 题解: 二分答案,检查有没有负环 #include<cstdio> #include<algorithm> ...

  4. POJ 3621 Sightseeing Cows 01分数规划,最优比例环的问题

    http://www.cnblogs.com/wally/p/3228171.html 题解请戳上面 然后对于01规划的总结 1:对于一个表,求最优比例 这种就是每个点位有benefit和cost,这 ...

  5. POJ 3621 Sightseeing Cows [最优比率环]

    感觉去年9月的自己好$naive$ http://www.cnblogs.com/candy99/p/5868948.html 现在不也是嘛 裸题,具体看学习笔记 二分答案之后判负环就行了 $dfs$ ...

  6. POJ 3621 Sightseeing Cows (bellman-Ford + 01分数规划)

    题意:给出 n 个点 m 条有向边,要求选出一个环,使得这上面 点权和/边权和 最大. 析:同样转成是01分数规划的形式,F / L 要这个值最大,也就是 G(r) = F - L * r 这个值为0 ...

  7. POJ 3621 Sightseeing Cows (最优比率环 01分数划分)

    题意: 给定L个点, P条边的有向图, 每个点有一个价值, 但只在第一经过获得, 每条边有一个花费, 每次经过都要付出这个花费, 在图中找出一个环, 使得价值之和/花费之和 最大 分析: 这道题其实并 ...

  8. [POJ 3621] Sighting Cows

    01分数规划的基本裸题. 因为路线一定是个环,所以找个最优比率生成环即可 二分一个比值,check一下即可. #include <queue> #include <cstdio> ...

  9. POJ3621 Sightseeing Cows 最优比率环 二分法

    题目链接:http://poj.org/problem?id=3621 Sightseeing Cows Time Limit: 1000MS   Memory Limit: 65536K Total ...

随机推荐

  1. div自动适应浏览器窗口水平和垂直居中

    html <body> <div id="centerDiv">自动适应水平和垂直居中</div> </body> css ;;} ...

  2. nodejs脚手架express-generator

    1.安装生成器 npm install express-generator -g 2. 创建名称为APP的应用: express my-project 3.安装依赖包 cd my-project np ...

  3. Inception搭建

    Inception安装Inception是集审核.执行.回滚于一体的一个自动化运维系统,它是根据MySQL代码修改过来的,用它可以很明确的,详细的,准确的审核MySQL的SQL语句,它的工作模式和My ...

  4. SmartUpload实现文件上传

    (一)SmartUpload组件简介 SmartUpload组件 专门用于实现文件上传及下载的免费组件   (二)SmartUpload组件特点 使用简单:编写少量代码,完成上传下载功能 能够控制上传 ...

  5. JAVA;使用java.awt.Image的不稳定性

    在使用awt的image时候,不是能时时获取到图像的宽和高, GetWidth()函数偶尔得到的值为-1,暂时没有找到解决方法. 代码: public class picture extends JF ...

  6. 前端工具gulp

    最近在写一个新的项目,用到了新框架,主要是:react+webpack.里面还用到了一个前端工具——gulp. gulp在项目里的作用是打包静态资源.编译less,压缩css等.js并不在处理之列(不 ...

  7. 三种办法来安装Python3.x

    Centos7默认自带了Python2.7版本,但是因为项目需要使用Python3.x你可以按照此文的三个方法进行安装. 注:本文示例安装版本为Python3.5, 一.Python源代码编译安装 安 ...

  8. eas之获取各模块系统状态信息

    public void getSystemStatue() throws EASBizException, BOSException    {        CompanyOrgUnitInfo co ...

  9. 分治FFT模板

    题目链接:https://www.luogu.org/problemnew/show/P4721 总结了一下蒟蒻FFT/NTT容易写错的地方: ​ 1.rev数组求错. ​ 2.cdq注意顺序:先递归 ...

  10. Java常量池详细说明

    java常量池技术  java中的常量池技术,是为了方便快捷地创建某些对象而出现的,当需要一个对象时,就可以从池中取一个出来(如果池中没有则创建一个),则在需要重复创建相等变量时节省了很多时间.常量池 ...