题目链接:

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. 5G

    前世 1G 2G 3G 4G 今生  5G 推荐书籍: Gold Smith -<无线通信> David Tse -<无线通信基础> 参考:

  2. EntityFrame Work 6 Code First 配置字段为varchar 类型

    EntityFrame Work 6 配置字符串属性是否支持Unicode 内容 默认情况下,字符串为Unicode(SQLServer 中的nvarchar).您可以使用IsUnicode 方法指定 ...

  3. sql语句查询

    1. sql语句查询某位数字或者某几位数字开头的数据,字段类型为数字类: %’: 2. sql搜索以4开头和含有李字的数据: select * from wlzbpre_user where real ...

  4. Difficult Melody(映射)

    题目链接 http://vjudge.net/contest/137242#problem/D Description You're addicted to a little game called ...

  5. php实现设计模式之 原型模式

    <?php /* * 原型模式:通过复制已经存在的对象来创建新对象. * 通过原型实例指定创建对象的种类,并且通过copy这些原型创建信的对象 * 是创建型模式 * 有的时候创建一个对象有很多步 ...

  6. 大公司c#&.net转型java的原因有哪些?

    历来就听说有编程语言“鄙视链”的说法,而如今月经贴上的那些事儿,还真让我给遇到了. 以下内容来自知乎,纯属扯淡,易引发口水战,看完勿人身攻击. 目的给盲目的公司决策者.开发人员科普下,有个客观清醒的认 ...

  7. Hibernate总结(一)

    Hibernate为了提高性能,提供了缓存与快照机制. 它的缓存分为一级缓存与二级缓存. Hibernate一级缓存:当一个事务中执行一次Sql语句时,就将返回的结果存储在Session中的Map集合 ...

  8. 浅谈tornado项目应用设计

    一.预备知识 最近开始尝试做一些tornado商城项目,在开始之前需要引入一些项目设计知识,如接口,抽象方法抽象类,组合,程序设计原则等,个人理解项目的合理设计可增加其灵活性,降低数据之间的耦合性,提 ...

  9. 基于WCF MSMQ 的企业应用解决方案

    最近研究了一下基于MSMQ的WCF应用,从书上.网上查了很多资料,但始终没能彻底理解WCF-MSMQ的工作原理,也没能得到一个合理的应用解决方案.索性还是自己做个实验,探索一下吧.经过反复试验,颇有收 ...

  10. 简要分析webpack打包后代码

    开门见山 1.打包单一模块 webpack.config.js module.exports = { entry:"./chunk1.js", output: { path: __ ...