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 si competitors 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条边,每个点有s个人,b个食物,每条单向边u,v,c,p,c为一条边最多经过c次,p为路断的概率,第一个人经过一定不会断,第二个人开始每个人有p的概率使得路断

问每个人都有食物并且使得破坏网络概率最小

题解

显然不能直接算路断的概率,要算最大不断概率,再用1-它

可以知道如果有a条边被破坏,那么概率就是(1-p)^a

最小费用流跑得是加法,显然得变成乘法,可以两边取对数log10,这样跑的话是最小不断概率,再同*-1,就可以得到最大了

还有一点第一个人经过不会断,可以单独拿1流量概率为0就行了

注意在SPFA跑的时候会有浮点数的比较,需要加1个eps,不然会TLE

答案就是10^(-最大不断概率)

代码

 #include<bits/stdc++.h>
using namespace std; const int N=1e5+;
const int M=2e5+;
const int INF=0x3f3f3f3f; int FIR[N],FROM[M],TO[M],CAP[M],FLOW[M],NEXT[M],tote;
double COST[M],dist[N];
int pre[N],q[];
bool vis[N];
int n,m,S,T;
void init()
{
tote=;
memset(FIR,-,sizeof(FIR));
}
void addEdge(int u,int v,int cap,double cost)
{
FROM[tote]=u;
TO[tote]=v;
CAP[tote]=cap;
FLOW[tote]=;
COST[tote]=cost;
NEXT[tote]=FIR[u];
FIR[u]=tote++; FROM[tote]=v;
TO[tote]=u;
CAP[tote]=;
FLOW[tote]=;
COST[tote]=-cost;
NEXT[tote]=FIR[v];
FIR[v]=tote++;
}
bool SPFA(int s, int t)
{
for(int i=;i<=n+;i++)
{
dist[i]=1e9;
vis[i]=;
pre[i]=-;
}
dist[s]=;vis[s]=true;q[]=s;
int head=,tail=;
while(head!=tail)
{
int u=q[++head];vis[u]=false;
for(int v=FIR[u];v!=-;v=NEXT[v])
{
if(dist[TO[v]]>dist[u]+COST[v]+1e-&&CAP[v]>FLOW[v])
{
dist[TO[v]]=dist[u]+COST[v];
pre[TO[v]]=v;
if(!vis[TO[v]])
{
vis[TO[v]] = true;
q[++tail]=TO[v];
}
}
}
}
return pre[t]!=-;//可达返回true
}
void MCMF(int s, int t, double &cost, int &flow)
{
flow=;
cost=;
while(SPFA(s,t))
{
int Min=INF;
for(int v=pre[t];v!=-;v=pre[TO[v^]])
Min=min(Min,CAP[v]-FLOW[v]);
for(int v=pre[t];v!=-;v=pre[TO[v^]])
{
FLOW[v]+=Min;
FLOW[v^]-=Min;
cost+=COST[v]*Min;
}
flow+=Min;
}
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
init();
S=,T=n+;
for(int i=,s,b;i<=n;i++)
{
scanf("%d%d",&s,&b);
if(s>b)addEdge(S,i,s-b,0.0);
if(s<b)addEdge(i,T,b-s,0.0);
}
double p;
for(int i=,u,v,c;i<m;i++)
{
scanf("%d%d%d%lf",&u,&v,&c,&p);
if(c>)addEdge(u,v,,0.0);
if(c>)addEdge(u,v,c-,-log10(1.0-p));
}
int flow;
double cost;
MCMF(S,T,cost,flow);
printf("%.2f\n",1.0-pow(10.0,-cost));
}
return ;
}

HDU 5988 Coding Contest(最小费用最大流变形)的更多相关文章

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

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

  2. HDU5988/nowcoder 207G - Coding Contest - [最小费用最大流]

    题目链接:https://www.nowcoder.com/acm/contest/207/G 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5988 ...

  3. HDU–5988-Coding Contest(最小费用最大流变形)

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

  4. hdu 1533 Going Home 最小费用最大流

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1533 On a grid map there are n little men and n house ...

  5. hdu 3667(拆边+最小费用最大流)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3667 思路:由于花费的计算方法是a*x*x,因此必须拆边,使得最小费用流模板可用,即变成a*x的形式. ...

  6. hdu 3488(KM算法||最小费用最大流)

    Tour Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submis ...

  7. hdu 3395(KM算法||最小费用最大流(第二种超级巧妙))

    Special Fish Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  8. hdu 1533 Going Home 最小费用最大流 入门题

    Going Home Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  9. POJ 2195 & HDU 1533 Going Home(最小费用最大流)

    这就是一道最小费用最大流问题 最大流就体现到每一个'm'都能找到一个'H',但是要在这个基础上面加一个费用,按照题意费用就是(横坐标之差的绝对值加上纵坐标之差的绝对值) 然后最小费用最大流模板就是再用 ...

随机推荐

  1. hibernate模拟(转载)

    package simulation; /** * * @author Administrator * */ public class User { private int id; private S ...

  2. 全志A33开发板Linux内核定时器编程

    开发平台 * 芯灵思SinlinxA33开发板 淘宝店铺: https://sinlinx.taobao.com/ 嵌入式linux 开发板交流 QQ:641395230 Linux 内核定时器是内核 ...

  3. PythonStudy——阶段总结

    每个数据类型的最大特点是什么? (1)int整型:用于存放整形对象,是不可变类型.若将一个整数赋值给一个变量名,python可自动将其设置为int型. 例如:age = 30 这里的age对象的typ ...

  4. 小程序通过background-image设置背景图片

    微信小程序通过background-image设置背景:只支持线上图片和base64图片,不支持本地图片:base64图片设置步骤如下: 1.在网站http://imgbase64.duoshiton ...

  5. because there was insufficient free space available after evicting expired cache entries

    Tomcat运行的时候哗哗哗的报警告 版本是Tomcat 8.5.15 告警信息关键字如下 because there was insufficient free space available af ...

  6. python之路——14

    王二学习python的笔记以及记录,如有雷同,那也没事,欢迎交流,wx:wyb199594 复习 1.迭代器 1.双下方法:不常直接调用,是通过其他语法触发的 2.可迭代的:可迭代协议——含有__it ...

  7. iOS上传本地代码到git

    1.顾名思义,首先你得注册一个github账户 这个我就不细说了. 2.然后你得创建一个 repository  步骤见下图 3.相当于创建成功 会跳到下图界面 4.一看就很清楚了 create a ...

  8. Nginx、HAProxy、LVS三者的优缺点

    一.Nginx优点: 1.工作在网络7层之上,可针对http应用做一些分流的策略,如针对域名.目录结构,它的正规规则比HAProxy更为强大和灵活,所以,目前为止广泛流行. 2.Nginx对网络稳定性 ...

  9. sql使用实例

    将另一表中的合计值保存到指定字段,并将空值赋0 update ShopInfo set JLRunningWater =(select COALESCE(sum(v.TotalMoney),0) as ...

  10. html5 + thyleaf引擎

    偶然与巧合 舞动了蝶翼 谁的心头风起 前赴而后继 万千人追寻 荒漠唯一菩提 似擦肩相遇 或擦肩而去 命运犹如险棋 无数时间线 无数可能性 终于交织向你