题目链接:

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 <asp:Content>控件

    <asp:Content ID="Content2" ContentPlaceHolderID="CPH_MainContent" runat=" ...

  2. 基于CkEditor实现.net在线开发之路(3)常用From表单控件介绍与说明

    上一章已经简单介绍了CKEditor控件可以编写C#代码,然后可以通过ajax去调用,但是要在网页上面编写所有C#后台逻辑,肯定痛苦死了,不说实现复杂的逻辑,就算实现一个简单增删改查,都会让人头痛欲裂 ...

  3. 学习笔记之-------UIScrollView 基本用法 代理使用

    //contentSize.contentInset和contentOffset 是 scrollView三个基本的属性. // 滚动 self.ScrollView.contentSize =sel ...

  4. Class.forName("com.mysql.jdbc.Driver") ;

    try { Class.forName("com.mysql.jdbc.Driver") ; } catch(ClassNotFoundException e) { System. ...

  5. linux 下添加库的加载路径的方式

    linux 下有两种添加加载库路径的方式: 1.修改环境变量: export LD_LIBRARY_PATH=path_name 2.修改配置文件 修改 /etc/ld.so.conf 的内容在最后添 ...

  6. Java--正则表达式-简单的在字符串中找数字

    import org.junit.Test; import java.util.regex.Matcher; import java.util.regex.Pattern; public class ...

  7. 国内IT软件开发人员现状

             首先在这里讨论的是国内的大陆地区.在今天这个中国IT环境下,开发人员出路何在?一个优秀开发人,应该有致力于编写优雅代码,让别人读得懂,具有可读性,可测试性的代码,不仅仅是可以运行的代 ...

  8. JavaScript利用装饰模拟实现私有状态

    在经典的面向对象编程中,经常需要将对象的某个状态封装或隐藏在对象内,只有通过对象的一幅幅和能访问这些状态,对外只暴露一些重要的状态变量可以直接读写. 我们可以通过将变量(或参数)装饰在一个构造函数内来 ...

  9. 十二种获取Spring的上下文环境ApplicationContext的方法

    转载:https://my.oschina.net/u/2391658/blog/729414

  10. Android—基于Socket与上传图片到客户端

    最近项目中需要客户端和Socket互相传递数据时候需要相互传递图片所以做下总结以免以后忘记,也希望给大家带来帮助. 先上客户端的代码: 根据图片名称上传照相机中单个照片(此方法为自己封装) 参数所代表 ...