题目链接:

Coding Contest

Time Limit: 2000/1000 MS (Java/Others)   

 Memory Limit: 65536/65536 K (Java/Others)

Problem Description
A coding contest will be held in this university, in a huge playground. The whole playground would be divided into N blocks, and there would be M directed paths linking these blocks. The i-th path goes from the ui-th block to the vi-th block. Your task is to solve the lunch issue. According to the arrangement, there are sicompetitors in the i-th block. Limited to the size of table, bi bags of lunch including breads, sausages and milk would be put in the i-th block. As a result, some competitors need to move to another block to access lunch. However, the playground is temporary, as a result there would be so many wires on the path.
For the i-th path, the wires have been stabilized at first and the first competitor who walker through it would not break the wires. Since then, however, when a person go through the i - th path, there is a chance of pi to touch
the wires and affect the whole networks. Moreover, to protect these wires, no more than ci competitors are allowed to walk through the i-th path.
Now you need to find a way for all competitors to get their lunch, and minimize the possibility of network crashing.
 
Input
The first line of input contains an integer t which is the number of test cases. Then t test cases follow.
For each test case, the first line consists of two integers N (N ≤ 100) and M (M ≤ 5000). Each of the next N lines contains two integers si and bi (si , bi ≤ 200).
Each of the next M lines contains three integers ui , vi and ci(ci ≤ 100) and a float-point number pi(0 < pi < 1).
It is guaranteed that there is at least one way to let every competitor has lunch.
 
Output
For each turn of each case, output the minimum possibility that the networks would break down. Round it to 2 digits.
 
Sample Input
1
4 4
2 0
0 3
3 0
0 3
1 2 5 0.5
3 2 5 0.5
1 4 5 0.5
3 4 5 0.5
 
Sample Output
0.50
 
题意:
给出n个点和m条边,每个点有si个人,bi份食物,每条边一开始可以通过一个人,后来的人每通过一个就有pi的概率使整个系统崩溃,问崩溃的最小的概率是多少;
 
思路:
求出概率后取log后变成了费用流的模型,然后一搞就好了,RP如此重要;
 
AC代码:
#include <bits/stdc++.h>
using namespace std;
const int maxn=500;
const double inf=1e9;
const double eps=1e-8;
struct Edge
{
int from,to,cap,flow;
double cost;
};
int n,m,s,t,M;
std::vector<int> G[maxn];
std::vector<Edge> edge;
int inq[maxn],a[maxn],p[maxn];
double d[maxn];
inline void add_edge(int from,int to,int cap,double cost)
{
edge.push_back((Edge){from,to,cap,0,cost});
edge.push_back((Edge){to,from,0,0,-cost});
m=edge.size();
G[from].push_back(m-2);
G[to].push_back(m-1);
}
bool bellmanford(int &flow,double &cost)
{
for(int i=0;i<=t+1;i++)d[i]=inf;
memset(inq,0,sizeof(inq));
d[s]=0;inq[s]=1;p[s]=0;a[s]=inf;
queue<int>qu;
qu.push(s);
while(!qu.empty())
{
int fr=qu.front();qu.pop();
inq[fr]=0;
int len=G[fr].size();
for(int i=0;i<len;i++)
{
Edge& e=edge[G[fr][i]];
if(e.cap>e.flow&&d[e.to]>d[fr]+e.cost+eps)
{
d[e.to]=d[fr]+e.cost;
p[e.to]=G[fr][i];
a[e.to]=min(a[fr],e.cap-e.flow);
if(!inq[e.to]){qu.push(e.to);inq[e.to]=1;}
}
}
}
if(d[t]>=inf)return false;
flow+=a[t];
cost+=d[t]*a[t];
int u=t;
while(u!=s)
{
edge[p[u]].flow+=a[t];
edge[p[u]^1].flow-=a[t];
u=edge[p[u]].from;
}
return true;
}
double mincostflow()
{
int flow=0;double cost=0;
while(bellmanford(flow,cost));
return cost;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int u,v,w;
double xp;
scanf("%d%d",&n,&M);
s=0,t=n+1;
edge.clear();
for(int i=0;i<=t;i++)G[i].clear();
for(int i=1;i<=n;i++)
{
scanf("%d%d",&u,&v);
add_edge(s,i,u,0.0);
add_edge(i,t,v,0.0);
}
for(int i=1;i<=M;i++)
{
scanf("%d%d%d%lf",&u,&v,&w,&xp);
xp=-log(1-xp);
add_edge(u,v,w-1,xp);
add_edge(u,v,1,0.0);
}
//cout<<"&&&&\n";
double ans=-mincostflow();
printf("%.2f\n",1-exp(ans));
}
return 0;
}

  

hdu-5988 Coding Contest(费用流)的更多相关文章

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

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

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

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

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

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

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

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

  5. Coding Contest(费用流变形题,double)

    Coding Contest http://acm.hdu.edu.cn/showproblem.php?pid=5988 Time Limit: 2000/1000 MS (Java/Others) ...

  6. 2016青岛区域赛.Coding Contest(费用流 + 概率计算转换为加法计算)

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

  7. HDU5988 - 2016icpc青岛 - G - Coding Contest 费用流(利用对数化乘为加

    HDU5988 题意: 有n个区域,每个区域有s个人,b份饭.现在告诉你每个区域间的有向路径,每条路有容量和损坏路径的概率.问如何走可以使得路径不被破坏的概率最小.第一个人走某条道路是百分百不会损坏道 ...

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

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

  9. HDU5988 Coding Contest(费用流)

    2016青岛现场赛的一题,由于第一次走过不会产生影响,需要拆点,不过比赛时没想到,此外还有许多细节要注意,如要加eps,时间卡得较紧要注意细节优化等 #include <iostream> ...

随机推荐

  1. ASP.NET MVC 解析模板生成静态页一(RazorEngine)

    简述 Razor是ASP.NET MVC 3中新加入的技术,以作为ASPX引擎的一个新的替代项.在早期的MVC版本中默认使用的是ASPX模板引擎,Razor在语法上的确不错,用起来非常方便,简洁的语法 ...

  2. C#开发微信门户及应用(29)--微信个性化菜单的实现

    有一段时间没有接着微信的主题继续介绍里面的功能模块了,这段时间来,微信也做了不少的变化改动,针对这些特性我全面核对了一下相关的微信公众号和企业号的接口,对原有的微信API和系统管理做了全面的更新,本随 ...

  3. 【开源】SoDiaoEditor 可能是目前最好用的开源电子病历编辑器(B/S架构)

    此刻我的内心是忐忑的,这个标题给了我很大的压力,虽然很久以前我就在github上搜索一圈了,也没发现有其他更好的开源电子病历编辑器,如各位亲发现有更好的,烦请知会我一声. 该编辑器其实已经憋了很久了, ...

  4. PHP运行环境,服务器相关配置

    1.在DOS命令窗口输入 mysql -hlocalhost -uroot -p回车 进入mysql数据库, 其中-h表示服务器名,localhost表示本地:-u为数据库用户名,root是mysql ...

  5. Codeforces Round #234A

    Inna and choose option     题意: 一个由12个字符('O'或'X')组成的字符串,这12个字符可以排列成a*b(a*b=12)的矩阵,要求矩阵某一列都是'X'.用户输入t个 ...

  6. python批量下载图片的三种方法

    一是用微软提供的扩展库win32com来操作IE: win32com可以获得类似js里面的document对象,但貌似是只读的(文档都没找到). 二是用selenium的webdriver: sele ...

  7. 基于SSH框架的学生公寓管理系统的质量属性

    系统名称:学生公寓管理系统 首先介绍一下学生公寓管理系统,在学生公寓管理方面,针对学生有关住宿信息问题进行管理,学生公寓管理系统主要包含了1)学生信息记录:包括学号.姓名.性别.院系.班级:2)住宿信 ...

  8. HBase数据库集群配置

    0,HBase简介 HBase是Apache Hadoop中的一个子项目,是一个HBase是一个开源的.分布式的.多版本的.面向列的.非关系(NoSQL)的.可伸缩性分布式数据存储模型,Hbase依托 ...

  9. iOS crash 追终 ,iOS 如何定位crash 位置

    https://developer.apple.com/library/ios/technotes/tn2151/_index.html 错误分析是基于设备中的crash log 与 编译文件时生成的 ...

  10. (五)Maven目录结构及常用命令说明

    前面提到的部分知识有涉及到Maven目录结构与Maven常用的一些命令,在这里专门给大家做个简单的介绍. 1.Maven目录结构说明 Maven总体目录结构如下图: bin目录:该目录包含了mvn运行 ...