[题目链接]

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. 自动换行 word-break:break-all和word-wrap:break-word

    1.word-break:break-all;当内容(比如很长的一个单词)到每行的末端时,它会把单词截断显示一部分,下一行显示后一部分. 2.word-wrap:break-word;当内容(比如很长 ...

  2. Android Retrofit 2.0文件上传

    Android Retrofit 实现(图文上传)文字(参数)和多张图片一起上传 使用Retrofit进行文件上传,肯定离不开Part & PartMap. public interface ...

  3. RunLoop相关知识

    RunLoop,翻译过来是运行环路.我们在创建命令行项目和创建ios项目时,发现命令行项目当最后一行代码执行完后项目就自动退出了,而ios项目确可以一直运行,知道用户手动点击退出按钮.这就是因为ios ...

  4. 在Unity中客户端与服务器端的2种通信方式(Socker)

    15:17 2019/5/10 //第一种 using UnityEngine; using System.Collections; //引入库 using System.Net; using Sys ...

  5. 10.shard、replica机制及单node下创建index

    主要知识点     1.shard&replica机制梳理 2.单node环境下创建index的情况     1.shard&replica机制再次梳理     (1)index包含多 ...

  6. 强大的jQuery图片查看器插件Viewer.js

    简介 Viewer.js 是一款强大的图片查看器 Viewer.js 有以下特点: 支持移动设备触摸事件 支持响应式 支持放大/缩小 支持旋转(类似微博的图片旋转) 支持水平/垂直翻转 支持图片移动 ...

  7. Golang - 面对"对象"

    目录 Golang - 面对"对象" 1. 简介 2. 匿名字段 3. 方法 4. 包和封装 5. 接口 4. 包和封装 5. 接口 Golang - 面对"对象&quo ...

  8. luogu P4238 多项式求逆 (模板题、FFT)

    手动博客搬家: 本文发表于20181125 13:21:46, 原地址https://blog.csdn.net/suncongbo/article/details/84485718 题目链接: ht ...

  9. 洛谷 P1903 BZOJ 2120 清橙 A1274【模板】分块/带修改莫队(数颜色)(周奕超)

    试题来源 2011中国国家集训队命题答辩 题目描述 墨墨购买了一套N支彩色画笔(其中有些颜色可能相同),摆成一排,你需要回答墨墨的提问.墨墨会像你发布如下指令: 1. Q L R代表询问你从第L支画笔 ...

  10. fzu 2136

    #include<stdio.h> #define inf 1000000000 #define N 110000 int a[N]; struct node { int start,en ...