题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5988

哇,以前的模版一直T,加了优先队列优化才擦边过。

建图很好建,概率乘法化成概率加法不会化。

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
using namespace std;
const int maxn = ;
const int INF = 1e9;
double dist[maxn];
int tot,head[maxn];
int pv[maxn],pe[maxn];
typedef pair<double,int> P;
double eps = 1e-;
struct edge
{
int to,pre,cap;
double cost;
}e[];
void init()
{
tot = ;
memset(head,-,sizeof(head));
}
void add(int from,int to,int cap,double cost)
{
e[tot].pre = head[from];
e[tot].to = to;
e[tot].cap = cap;
e[tot].cost = cost;
head[from] = tot++;
}
void addedge(int from,int to,int cap,double cost)
{
add(from,to,cap,cost);
add(to,from,,-cost);
}
int n;
double min_cost_flow(int s,int t,int f,int& max_flow)
{
double ret = 0.0;
while(f>)
{
priority_queue<P,vector<P>,greater<P> >q;
for(int i=;i<maxn;i++) dist[i] = INF;
dist[s] = 0.0;
q.push(P(,s));
while(!q.empty())
{
P cur = q.top(); q.pop();
int v = cur.second;
if(dist[v]<cur.first) continue;
for(int i=head[v];i>=;i=e[i].pre)
{
int to = e[i].to,cap = e[i].cap;
double cost = e[i].cost;
if(cap>&&(dist[to]-(dist[v]+cost))>=eps)
{
pv[to] = v,pe[to] = i;
dist[to] = dist[v] + cost;
q.push(P(dist[to],to));
}
}
}
if(fabs(dist[t]-INF)<=eps) return ret;///同一目的地,每次增广路都是最小费用
///当所有边的流量都流净后,即没有残余网络,返回。
int d = f;
for(int v=t;v!=s;v=pv[v])
{
d = min(d,e[pe[v]].cap);
}
f -= d;
max_flow += d;
ret += (double)d*dist[t]; ///走一单位就消耗dist[t]
for(int v=t;v!=s;v=pv[v])
{
e[pe[v]].cap -= d;
e[pe[v]^].cap += d;
}
}
return ret;
}
int main()
{
int T;scanf("%d",&T);
while(T--)
{
int m;
init();
scanf("%d %d",&n,&m);
int s = n+;
int t = n+;
for(int i=;i<=n;i++)
{
int si,bi;
scanf("%d %d",&si,&bi);
int x = si-bi;
if(x>) addedge(s,i,x,);
else if(x<) addedge(i,t,-x,);
}
int u,v,c;
double p;
for(int i=;i<=m;i++)
{
scanf("%d %d %d %lf",&u,&v,&c,&p);
p = -1.0*log2(1.0-p);
if(c>)
{
addedge(u,v,,);///第一个人不用费用
}
if(c->)
{
addedge(u,v,c-,p);
}
}
int max_flow = ;
double cost = min_cost_flow(s,t,INF,max_flow);
double di = 2.0;
printf("%.2f\n",(1.0-pow(di,-cost)));
}
return ;
}

HDU 5988最小网络流(浮点数)的更多相关文章

  1. HDU 3452 Bonsai(网络流之最小割)

    题目地址:HDU 3452 最小割水题. 源点为根节点.再另设一汇点,汇点与叶子连边. 对叶子结点的推断是看度数是否为1. 代码例如以下: #include <iostream> #inc ...

  2. HDU 3046Pleasant sheep and big big wolf(切最小网络流)

    职务地址:HDU 3046 最小割第一发!事实上也没什么发不发的. ..最小割==最大流.. 入门题,可是第一次入手最小割连入门题都全然没思路... sad..对最小割的本质还是了解的不太清楚.. 这 ...

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

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

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

    http://acm.split.hdu.edu.cn/showproblem.php?pid=5988 题意:在acm比赛的时候有多个桌子,桌子与桌子之间都有线路相连,每个桌子上会有一些人和一些食物 ...

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

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

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

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

  7. 【网络流#2】hdu 1533 - 最小费用最大流模板题

    最小费用最大流,即MCMF(Minimum Cost Maximum Flow)问题 嗯~第一次写费用流题... 这道就是费用流的模板题,找不到更裸的题了 建图:每个m(Man)作为源点,每个H(Ho ...

  8. HDU 1533 最小费用最大流(模板)

    http://acm.hdu.edu.cn/showproblem.php?pid=1533 这道题直接用了模板 题意:要构建一个二分图,家对应人,连线的权值就是最短距离,求最小费用 要注意void ...

  9. HDU 3374 最小/大表示法+KMP

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3374 题意:给定一个串s,该串有strlen(s)个循环同构串,要求输出字典序最小的同构串的下标,字典 ...

随机推荐

  1. Golang TCP转发到指定地址

    Golang TCP转发到指定地址 第二个版本,设置指定ip地址 代码 // tcpForward package main import ( "fmt" "net&qu ...

  2. php 关于金额的几种计算方式

    php 关于金额的几种计算方式 平常开始开发过程中,多多少少都会遇到点关于金额的计算,比如设置返利.提现手续费.折扣啊等等诸如此类的比例,然后再计算出之后的实际的费用. 下面,以折扣为例,来实现这类计 ...

  3. 12.Yii2.0框架视图模版继承与模版相互调用

    目录 模板渲染的两种方式 加载视图 index.php 和 about.php 页面 建立控制器HomeController php 新建模板 home\index.php 新建模板home\abou ...

  4. Applied Nonparametric Statistics-lec8

    Ref:https://onlinecourses.science.psu.edu/stat464/print/book/export/html/11 additive model value = t ...

  5. python3与python2的编码问题

    在讲这个问题之前,我们先说说unicode的工作原理.unicode包含了跟全球所有国家编码的映射关系,就是不管你用哪个国家的编码,unicode都能找到它在unicode中的编码.那么无论你用什么编 ...

  6. poj-3009 curling2.0(搜索)

    Curling 2.0 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 26408   Accepted: 10546 Des ...

  7. POJ:1751-Highways(Kruskal和Prim)

    Highways Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6078 Accepted: 1650 Special Judg ...

  8. Mysql源码编译安装&主从复制

    一)camke源码编译安装mysql 1)创建软件安装目录software [root@master software]# ls cmake-2.8.8.tar.gz mysql-5.5.32.tar ...

  9. HDU 1533 二分图最小权匹配 Going Home

    带权二分图匹配,把距离当做权值,因为是最小匹配,所以把距离的相反数当做权值求最大匹配. 最后再把答案取一下反即可. #include <iostream> #include <cst ...

  10. Ubuntu 档案权限

    Linux文件属性:查看指令是:ls -al ls是list的意思,重点在显示档案的文件名与相关属性.而选项-al则表示列出所有的档案详细的权限与属性.