题目链接: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. Hogan的安装和使用

    Hogan的安装和使用 通过npm安装hogan: npm install hogan.js --save-dev CommonJs下的使用方式: // 引入hogan var hogan = req ...

  2. Lecture 3

    surface models 1. The two main methods of creating surface models are interpolation and triangulatio ...

  3. POJ:1328-Radar Installation

    Radar Installation Time Limit: 1000MS Memory Limit: 10000K Description Assume the coasting is an inf ...

  4. Selenium2用最简xpath查找元素

    什么是xpath? 来自百度百科的解释:XPath即为XML路径语言,它是一种用来确定XML(标准通用标记语言的子集)文档中某部分位置的语言.XPath基于XML的树状结构,提供在数据结构树中找寻节点 ...

  5. poj1523赤裸裸的割点

    这题真是没什么好说的...赤裸裸的求割点直接模板上 #include<cstdio> #include<cstring> #include<iostream> #i ...

  6. CodeForces Round #320 Div2

    A. Raising Bacteria 计算一下x的bitcount就是答案. #include <iostream> #include <cstdio> #include & ...

  7. 使用百度siteapp开发网站的App-(IOS和Android版本)

    介绍 之前写了个把百度云作文网站文件服务器.一些园友的评论不错.不过我似乎把意思弄错了!  我用的百度云的SVN环境! 现在不少人都做web开发.不管你是什么语言编写的(jsp,php,asp.net ...

  8. adb devices 找不到夜神模拟器解决方法

    先打开命令行窗口,输入adb devices,查看连接信息,大致意思是sdk的adb版本与夜神的adb版本不一致,导致. C:\Users\cz9025>adb devices List of ...

  9. OA笔记

    一:Asp.Net MVC请求处理原理(Asp.Net mvc 是怎样进入请求管道的.)请求-->IIS--->ISAPIRuntime-->HttpWorkRequest--> ...

  10. POJ 1315 Don't Get Rooked

    Don't Get Rooked Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2086   Accepted: 1325 ...