http://acm.split.hdu.edu.cn/showproblem.php?pid=5988

题意:
在acm比赛的时候有多个桌子,桌子与桌子之间都有线路相连,每个桌子上会有一些人和一些食物,现在要吃午饭了,有些人就可能需要到别的桌子去拿食物,但是必须沿着线路走,每根线路第一个人走时没事,接下来的人走时会有一定概率使网络瘫痪,并且每根线路最多可以走c人。现在问使网络瘫痪的最低概率是多少?

思路:
建立费用流,由于概率是要相乘,这里可以转换成log后进行计算,最后再转换回来即可。

由于这题是浮点数,所以在松弛的时候需要加eps,否则会TLE。

 #include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<int,int> pll;
const int INF = 0x3f3f3f3f;
const int maxn = +;
const double eps = 1e-; int n,m; struct Edge
{
int from, to, cap, flow;
double cost;
Edge(int u, int v, int c, int f, double w) :from(u), to(v), cap(c), flow(f), cost(w) {}
}; struct MCMF
{
int n, m;
vector<Edge> edges;
vector<int> G[maxn];
int inq[maxn];
double d[maxn];
int p[maxn];
int a[maxn]; void init(int n)
{
this->n = n;
for (int i = ; i<n; i++) G[i].clear();
edges.clear();
} void AddEdge(int from, int to, int cap, double cost)
{
edges.push_back(Edge(from, to, cap, , cost));
edges.push_back(Edge(to, from, , , -cost));
m = edges.size();
G[from].push_back(m - );
G[to].push_back(m - );
} bool BellmanFord(int s, int t, int &flow, double & cost)
{
for (int i = ; i<n; i++) d[i] = INF;
memset(inq, , sizeof(inq));
d[s] = ; inq[s] = ; p[s] = ; a[s] = INF; queue<int> Q;
Q.push(s);
while (!Q.empty()){
int u = Q.front(); Q.pop();
inq[u] = ;
for (int i = ; i<G[u].size(); i++){
Edge& e = edges[G[u][i]];
if (e.cap>e.flow && d[e.to]>d[u] + e.cost +eps){
d[e.to] = d[u] + e.cost;
p[e.to] = G[u][i];
a[e.to] = min(a[u], e.cap - e.flow);
if (!inq[e.to]) { Q.push(e.to); inq[e.to] = ; }
}
}
} if (d[t] == INF) return false;
flow += a[t];
cost += d[t] * a[t];
for (int u = t; u != s; u = edges[p[u]].from)
{
edges[p[u]].flow += a[t];
edges[p[u] ^ ].flow -= a[t];
}
return true;
} double MincostMaxdflow(int s, int t){
int flow = ;
double cost = ;
while (BellmanFord(s, t, flow, cost));
return cost;
}
}t; int a[maxn],b[maxn],c[maxn]; int main()
{
//freopen("in.txt","r",stdin);
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
int src=,dst=*n+;
t.init(dst+);
for(int i=;i<n;i++)
{
scanf("%d%d",&a[i],&b[i]);
c[i]=a[i]-b[i];
if(c[i]<) t.AddEdge(i+,dst,-c[i],);
else if(c[i]>) t.AddEdge(src,i+,c[i],);
}
for(int i=;i<m;i++)
{
int u,v,c; double p;
scanf("%d%d%d%lf",&u,&v,&c,&p);
p=-log(-p);
if(c==) continue;
if(c==) t.AddEdge(u,v,,);
else if(c>)
{
t.AddEdge(u,v,,);
t.AddEdge(u,v,c-,p);
}
}
double ans = t.MincostMaxdflow(src,dst);
ans=exp(-ans);
printf("%.2f\n",-ans);
}
return ;
}

HDU 5988 Coding Contest(浮点数费用流)的更多相关文章

  1. HDU 5988.Coding Contest 最小费用最大流

    Coding Contest Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)To ...

  2. HDU 5988 Coding Contest(最小费用最大流变形)

    Problem DescriptionA coding contest will be held in this university, in a huge playground. The whole ...

  3. HDU 5988 Coding Contest(费用流+浮点数)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5988 题目大意: 给定n个点,m条有向边,每个点是一个吃饭的地方,每个人一盒饭.每个点有S个人,有B盒 ...

  4. HDU 5988 Coding Contest 最小费用流 cost->double

    Problem Description A coding contest will be held in this university, in a huge playground. The whol ...

  5. HDU5988/nowcoder 207G - Coding Contest - [最小费用最大流]

    题目链接:https://www.nowcoder.com/acm/contest/207/G 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5988 ...

  6. HDU 5644 King's Pilots 费用流

    King's Pilots 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5644 Description The military parade w ...

  7. HDU 3667 Transportation(网络流之费用流)

    题目地址:HDU 3667 这题的建图真是巧妙...为了保证流量正好达到k.须要让每一次增广到的流量都是1,这就须要把每一条边的流量都是1才行.可是每条边的流量并非1,该怎么办呢.这个时候能够拆边,反 ...

  8. 【进阶——最小费用最大流】hdu 1533 Going Home (费用流)Pacific Northwest 2004

    题意: 给一个n*m的矩阵,其中由k个人和k个房子,给每个人匹配一个不同的房子,要求所有人走过的曼哈顿距离之和最短. 输入: 多组输入数据. 每组输入数据第一行是两个整型n, m,表示矩阵的长和宽. ...

  9. HDU 3488--Tour(KM or 费用流)

    因为每个点只能经过一次 所以考虑拆点 这题有坑,有重边.. KM算法 把一个点拆成入点和出点 入点在X部,出点在Y步. 如果u,v之间有路径,就在X部的u点连接Y部的v点 求完美匹配. 当完美匹配的时 ...

随机推荐

  1. hibernate二级缓存ehcache hibernate配置详解

    <!-----------------hibernate二级缓存ehcache------------------------->hibernate配置 <prop key=&quo ...

  2. JustOj 1032: 习题6.7 完数

    题目描述 一个数如果恰好等于它的因子之和,这个数就称为"完数". 例如,6的因子为1.2.3,而6=1+2+3,因此6是"完数". 编程序找出N之内的所有完数, ...

  3. Inernet TLS协议注册表 开启

    IE高级配置中,存在SSL支持协议,例如SSL TLS. 其在注册表的路径为:HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\I ...

  4. vue style 的scoped 使用

    1 原理 vue 可以通过在 style标签添加scoped这个属性来控制 组件内的css作用域 <style scoped> @media (min-width: 250px) { .l ...

  5. linux释放页面缓存drop_caches

    关于drop_caches文件:系统默认为0 在Documentation/sysctl/vm.txt中有如下描述: drop_caches Writing to this will cause th ...

  6. .net下安装 ZooKeeper.Net

    PM> Install-Package ZooKeeper.Net正在尝试解析依赖项“log4net (≥ 1.2.10)”.正在安装“log4net 1.2.10”.已成功安装“log4net ...

  7. 【题解】Luogu P2073 送花

    原题传送门 这题需要用到Splay 我们用一棵splay维护金钱 考虑c<=1000000 我们珂以把每种价格现在对应的美丽值存在一个a数组中 这样讲有珂能不太清楚qaq,还是对着操作一个一个讲 ...

  8. 【题解】Luogu P1204 [USACO1.2]挤牛奶Milking Cows

    原题传送门:P1204 [USACO1.2]挤牛奶Milking Cows 实际是道很弱智的题目qaq 但窝还是觉得用珂朵莉树写会++rp(窝都初二了,还要考pj) 前置芝士:珂朵莉树 窝博客里对珂朵 ...

  9. 【4opencv】识别复杂的答题卡1(主要算法)

    一.问题提出 由于GPY进行了纠偏,所以在采集的时候,就已经获得了质量较高的答题卡图片 下一步就是需要从这张图片中,识别出人眼识别出来的那些信息,并且将这个过程尽可能地鲁棒化,提高识别的准确率. 二. ...

  10. 20145325张梓靖 《网络对抗技术》 PC平台逆向破解

    20145325张梓靖 <网络对抗技术> PC平台逆向破解 学习任务 shellcode注入:shellcode实际是一段代码,但却作为数据发送给受攻击服务器,将代码存储到对方的堆栈中,并 ...