HDU 5988 Coding Contest(最小费用最大流变形)
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(最小费用最大流变形)的更多相关文章
- HDU 5988.Coding Contest 最小费用最大流
Coding Contest Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)To ...
- HDU5988/nowcoder 207G - Coding Contest - [最小费用最大流]
题目链接:https://www.nowcoder.com/acm/contest/207/G 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5988 ...
- HDU–5988-Coding Contest(最小费用最大流变形)
Coding Contest Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)To ...
- 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 ...
- hdu 3667(拆边+最小费用最大流)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3667 思路:由于花费的计算方法是a*x*x,因此必须拆边,使得最小费用流模板可用,即变成a*x的形式. ...
- hdu 3488(KM算法||最小费用最大流)
Tour Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Submis ...
- hdu 3395(KM算法||最小费用最大流(第二种超级巧妙))
Special Fish Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- hdu 1533 Going Home 最小费用最大流 入门题
Going Home Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- POJ 2195 & HDU 1533 Going Home(最小费用最大流)
这就是一道最小费用最大流问题 最大流就体现到每一个'm'都能找到一个'H',但是要在这个基础上面加一个费用,按照题意费用就是(横坐标之差的绝对值加上纵坐标之差的绝对值) 然后最小费用最大流模板就是再用 ...
随机推荐
- Docker安装(一)
环境:CentOS release 6.9 (Final) 1.检查环境是否支持安装docker 1)系统内核是否是3.8或更高版本 uname -a (这个安装不了,内核版本不够) Linux ...
- 十七、springcloud(三)服务的注册与调用
1.启动服务注册中心Eureka(见上篇) 启动成功后,暂时无服务 2.项目框架 3.创建服务提供者(spring-cloud-houge-provider)jar a.application.pro ...
- Elasticsearch -- Head插件安装
安装Head插件 由于head插件本质上还是一个nodejs的工程,因此需要安装node,使用npm来安装依赖的包. <1>安装Node.js 下载解压 wget https://node ...
- ROS下利用realsense采集RGBD图像合成点云
摘要:在ROS kinetic下,利用realsense D435深度相机采集校准的RGBD图片,合成点云,在rviz中查看点云,最后保存成pcd文件. 一. 各种bug 代码编译成功后,打开rviz ...
- 彻底删除msde2008(请先在控制面板中卸载).bat
彻底删除msde2008(请先在控制面板中卸载).bat @echo offset /P dv=请确认强制删除MSDE2008(请先在控制面板中卸载),Y=删除,N=退出:if not defined ...
- ZooKeeper和CAP理论及一致性原则
一.CAP理论概述CAP理论告诉我们,一个分布式系统不可能同时满足以下三种 一致性(C:Consistency)可用性(A:Available)分区容错性(P:Partition Tolerance) ...
- springboot整合mybatis之注解方式
1. 创建maven项目,工程目录如下图 2. 在pom.xml文件中添加mybatis依赖. 3. 创建实体类,并生成construct方法,getter和setter方法.同时在数据库中创建对应的 ...
- WordPress版微信小程序开发系列(二):安装使用问答
自WordPress版微信小程序发布开源以来,受关注的程度超过我原来的想象.这套程序主要面对的用户是wordpress网站的站长,如果wordpress站想在微信的生态圈得到推广,小程序成为一种重要的 ...
- sweetalert弹窗的使用
之前接触到layer弹出层,今天又发现了一个非常实用的弹出层插件,它的名字叫做sweetalert. 官网地址:http://t4t5.github.io/sweetalert/ npm下载方式:np ...
- 时间的转化 js
php 和java是不一样的 PHP 需要先乘1000 java 不需要 因为PHP传过来的是十位数 java传过来是十三位数 function formatDate() { var now = n ...