嘟嘟嘟

这题好像属于01分数规划问题,叫什么最优比率生成环。

题目概括一下,就是求一个环,满足∑v[i] / ∑c[i]最大。

我们可以堆上面的式子变个型:令 x = ∑v[i] / ∑c[i],则x * ∑c[i] = v[i] => ∑x * c[i] - v[i] = 0。于是对于任何能取到的x',满足∑x * c[i] - v[i] <= 0;对于不能取到的x', ∑x * c[i] - v[i] > 0。

于可以实数二分答案,用spfa判断负环。

然后实数二分又RE了……调了好就还是看了题解。

 #include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<cctype>
#include<stack>
#include<queue>
#include<vector>
using namespace std;
#define enter puts("")
#define space putchar(' ')
#define Mem(a, x) memset(a, x, sizeof(a))
#define rg register
typedef long long ll;
typedef double db;
const int INF = 0x3f3f3f3f;
const db eps = 1e-;
const int maxn = 1e3 + ;
inline ll read()
{
ll ans = ;
char ch = getchar(), las = ' ';
while(!isdigit(ch)) las = ch, ch = getchar();
while(isdigit(ch)) ans = (ans << ) + (ans << ) + ch - '', ch = getchar();
if(las == '-') ans = -ans;
return ans;
}
inline void write(ll x)
{
if(x < ) putchar('-'), x = -x;
if(x >= ) write(x / );
putchar(x % + '');
} int n, m, val[maxn];
vector<int> v[maxn], c[maxn]; bool in[maxn];
db dis[maxn];
int cnt[maxn];
bool judge(db x)
{
Mem(in, ); Mem(cnt, ); Mem(dis, );
queue<int> q;
for(int i = ; i <= n; ++i) q.push(i);
while(!q.empty())
{
int now = q.front(); q.pop(); in[now] = ;
for(int i = ; i < (int)v[now].size(); ++i)
{
if(dis[v[now][i]] > x * c[now][i] - val[v[now][i]] + dis[now])
{
dis[v[now][i]] = x * c[now][i] - val[v[now][i]] + dis[now];
if(!in[v[now][i]])
{
if(++cnt[v[now][i]] == n - ) return ;
q.push(v[now][i]);
}
}
}
}
return ;
} int main()
{
n = read(); m = read();
for(int i = ; i <= n; ++i) val[i] = read();
for(int i = ; i <= m; ++i)
{
int x = read(), y = read(), co = read();
v[x].push_back(y); c[x].push_back(co);
}
db L = , R = 1e6;
while(R - L > eps)
{
db mid = (L + R) / ;
if(judge(mid)) L = mid;
else R = mid;
}
if(L < eps) write(), enter;
else printf("%.2lf\n", L);
return ;
}

[USACO07DEC]Sightseeing Cows的更多相关文章

  1. [USACO07DEC]Sightseeing Cows(负环,0/1分数规划)

    [USACO07DEC]Sightseeing Cows Description Farmer John has decided to reward his cows for their hard w ...

  2. P2868 [USACO07DEC]Sightseeing Cows G

    题意描述 Sightseeing Cows G 给定一张有向图,图中每个点都有点权 \(a_i\),每条边都有边权 \(e_i\). 求图中一个环,使 "环上个点权之和" 除以 & ...

  3. P2868 [USACO07DEC]观光奶牛Sightseeing Cows

    P2868 [USACO07DEC]观光奶牛Sightseeing Cows [](https://www.cnblogs.com/images/cnblogs_com/Tony-Double-Sky ...

  4. 洛谷P2868 [USACO07DEC]观光奶牛Sightseeing Cows

    P2868 [USACO07DEC]观光奶牛Sightseeing Cows 题目描述 Farmer John has decided to reward his cows for their har ...

  5. 【POJ3621】Sightseeing Cows

    Sightseeing Cows Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8331   Accepted: 2791 ...

  6. Sightseeing Cows(最优比率环)

    Sightseeing Cows Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8915   Accepted: 3000 ...

  7. 【POJ3621】Sightseeing Cows 分数规划

    [POJ3621]Sightseeing Cows 题意:在给定的一个图上寻找一个环路,使得总欢乐值(经过的点权值之和)/ 总时间(经过的边权值之和)最大. 题解:显然是分数规划,二分答案ans,将每 ...

  8. 【POJ3621】【洛谷2868】Sightseeing Cows(分数规划)

    [POJ3621][洛谷2868]Sightseeing Cows(分数规划) 题面 Vjudge 洛谷 大意: 在有向图图中选出一个环,使得这个环的点权\(/\)边权最大 题解 分数规划 二分答案之 ...

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

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

随机推荐

  1. Iterator和for...of循环

    Iterator和for...of循环 Iterator(遍历器)的概念 数据结构的默认Iterator接口 调用Iterator接口的场合 字符串的Iterator接口 Iterator接口与Gen ...

  2. 获取用户Ip地址通用方法常见安全隐患(HTTP_X_FORWARDED_FOR)

    分析过程 这个来自一些项目中,获取用户Ip,进行用户操作行为的记录,是常见并且经常使用的. 一般朋友,都会看到如下通用获取IP地址方法. function getIP() { if (isset($_ ...

  3. Navicat 大小写

    1.找到数据库表的存在位置 比如我的是C:\ProgramData\MySQL\MySQL Server 5.7\Data\tinysdpm 2.修改小写的表名称 比如customer_type.fr ...

  4. Expression Blend实例中文教程(12) - 样式和模板快速入门Style,Template

    在上一篇,介绍了Visual State Manager视觉状态管理器,其中涉及到控件的样式(Style)和模板(Template),本篇将详细介绍样式(Style)和模板(Template)在Sil ...

  5. 用 Redis Desktop Manager 远程连接 redis 数据库。

    环境: 本机OS:window 10(本机没有安装redis) redis 服务器:centos 7 使用 Redis Desktop Manager 工具远程连接 redis. Redis Desk ...

  6. javaweb带父标签的自定义标签

    1.完整的示例代码:要实现的功能是父标签中有name属性,子标签将父标签的name属性值打印到jsp页面上. 1.1 父类和子类的标签处理器类 testParentTag.java package c ...

  7. Golang 的 TOML库

    TOML 的全称是 Tom's Obvious, Minimal Language,因为它的作者是 GitHub 联合创始人 Tom Preston-Werner. TOML 的目标是成为一个极简的配 ...

  8. VUE的两种跳转push和replace对比区别

    router.push(location) 在vue.js中想要跳转到不同的 URL,需要使用 router.push 方法. 这个方法会向 history 栈添加一个新的记录,当用户点击浏览器后退按 ...

  9. 操作Hadoop集群

    操作Hadoop集群 所有必要的配置完成后,将文件分发到所有机器上的HADOOP_CONF_DIR目录.这应该是所有机器上相同的目录. 一般来说,建议HDFS和YARN作为单独的用户运行.在大多数安装 ...

  10. 数据结构----线性表顺序和链式结构的使用(c)

    PS:在学习数据结构之前,我相信很多博友也都学习过一些语言,比如说java,c语言,c++,web等,我们之前用的一些方法大都是封装好的,就java而言,里面使用了大量的封装好的方法,一些算法也大都写 ...