poj 3308(二分图的点权最小覆盖)
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 8325 | Accepted: 2502 |
Description
It is year 2500 A.D. and there is a terrible war between the forces of the Earth and the Mars. Recently, the commanders of the Earth are informed by their spies that the invaders of Mars want to land some paratroopers in the m × n grid yard of one their main weapon factories in order to destroy it. In addition, the spies informed them the row and column of the places in the yard in which each paratrooper will land. Since the paratroopers are very strong and well-organized, even one of them, if survived, can complete the mission and destroy the whole factory. As a result, the defense force of the Earth must kill all of them simultaneously after their landing.
In order to accomplish this task, the defense force wants to utilize some of their most hi-tech laser guns. They can install a gun on a row (resp. column) and by firing this gun all paratroopers landed in this row (resp. column) will die. The cost of installing a gun in the ith row (resp. column) of the grid yard is ri (resp. ci ) and the total cost of constructing a system firing all guns simultaneously is equal to the product of their costs. Now, your team as a high rank defense group must select the guns that can kill all paratroopers and yield minimum total cost of constructing the firing system.
Input
Input begins with a number T showing the number of test cases and then, T test cases follow. Each test case begins with a line containing three integers 1 ≤ m ≤ 50 , 1 ≤ n ≤ 50 and 1 ≤ l ≤ 500 showing the number of rows and columns of the yard and the number of paratroopers respectively. After that, a line with m positive real numbers greater or equal to 1.0 comes where the ith number is ri and then, a line with n positive real numbers greater or equal to 1.0 comes where the ith number is ci. Finally, l lines come each containing the row and column of a paratrooper.
Output
For each test case, your program must output the minimum total cost of constructing the firing system rounded to four digits after the fraction point.
Sample Input
1
4 4 5
2.0 7.0 5.0 2.0
1.5 2.0 2.0 8.0
1 1
2 2
3 3
4 4
1 4
Sample Output
16.0000 题意:一个矩阵,已知其中一些格会降落伞兵,每行每列都有一个武器,可以一次性消灭该行或该列的全部伞兵,每个武器对应不同的价格,若使用多个武器则总价是各个武器价钱的乘积,问消灭所有伞兵最少
要多少钱。
题解:上次看训练指南看到这个题的弱化版了,所以就马上知道用二分图的最小覆盖集来做,只不过这个题加了个条件,武器总价等于各个武器价格的乘积。。然后就卡住了,,结果找题解发现竟然是取对数将乘法
来做变成加法真的是好难想到啊 T_T 想到了就直接用 最小覆盖集 = 最小割 = 最大流来做了。。。
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <string.h>
#include <math.h>
#include <iostream>
#include <math.h>
using namespace std;
const int N = ;
const int INF = ;
struct Edge{
int v,next;
double w;
}edge[N*N];
int head[N];
int level[N];
int tot;
void init(){
memset(head,-,sizeof(head));
tot=;
}
void addEdge(int u,int v,double w,int &k){
edge[k].v = v,edge[k].w=w,edge[k].next=head[u],head[u]=k++;
edge[k].v = u,edge[k].w=,edge[k].next=head[v],head[v]=k++;
}
int BFS(int src,int des){
queue<int >q;
memset(level,,sizeof(level));
level[src]=;
q.push(src);
while(!q.empty()){
int u = q.front();
q.pop();
if(u==des) return ;
for(int k = head[u];k!=-;k=edge[k].next){
int v = edge[k].v;
double w = edge[k].w;
if(level[v]==&&w!=){
level[v]=level[u]+;
q.push(v);
}
}
}
return -;
}
double dfs(int u,int des,double increaseRoad){
if(u==des) return increaseRoad;
double ret=;
for(int k=head[u];k!=-;k=edge[k].next){
int v = edge[k].v;
double w = edge[k].w;
if(level[v]==level[u]+&&w!=){
double MIN = min(increaseRoad-ret,w);
w = dfs(v,des,MIN);
edge[k].w -=w;
edge[k^].w+=w;
ret+=w;
if(ret==increaseRoad) return ret;
}
}
return ret;
}
double Dinic(int src,int des){
double ans = ;
while(BFS(src,des)!=-) ans+=dfs(src,des,INF*1.0);
return ans;
} int main(){
int tcase;
scanf("%d",&tcase);
while(tcase--){
init();
int n,m,k;
double a[],b[];
scanf("%d%d%d",&n,&m,&k);
int src = ,des = n+m+;
double t;
for(int i=;i<=n;i++){
scanf("%lf",&t);
addEdge(src,i,log(t),tot);
}
for(int i=n+;i<=n+m;i++){
scanf("%lf",&t);
addEdge(i,des,log(t),tot);
}
while(k--){
int u,v;
scanf("%d%d",&u,&v);
addEdge(u,v+n,INF*1.0,tot);
}
printf("%.4lf\n",exp(Dinic(src,des)));
}
}
poj 3308(二分图的点权最小覆盖)的更多相关文章
- POJ - 3308 Paratroopers (最小点权覆盖)
题意:N*M个格点,K个位置会有敌人.每行每列都有一门炮,能打掉这一行(列)上所有的敌人.每门炮都有其使用价值.总花费是所有使用炮的权值的乘积.求最小的总花费. 若每门炮的权值都是1,就是求最小点覆盖 ...
- POJ 2125 Destroying the Graph 二分图最小点权覆盖
Destroying The Graph Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8198 Accepted: 2 ...
- POJ 2125 Destroying The Graph (二分图最小点权覆盖集+输出最小割方案)
题意 有一个图, 两种操作,一种是删除某点的所有出边,一种是删除某点的所有入边,各个点的不同操作分别有一个花费,现在我们想把这个图的边都删除掉,需要的最小花费是多少. 思路 很明显的二分图最小点权覆盖 ...
- POJ 2125 Destroying The Graph 二分图 最小点权覆盖
POJ2125 题意简述:给定一个有向图,要通过某些操作删除所有的边,每一次操作可以选择任意一个节点删除由其出发的所有边或者通向它的所有边,两个方向有不同的权值.问最小权值和的解决方案,要输出操作. ...
- POJ - 3308 Paratroopers(最大流)
1.这道题学了个单词,product 还有 乘积 的意思.. 题意就是在一个 m*n的矩阵中,放入L个敌军的伞兵,而我军要在伞兵落地的瞬间将其消灭.现在我军用一种激光枪组建一个防御系统,这种枪可以安装 ...
- POJ2125 Destroying The Graph(二分图最小点权覆盖集)
最小点权覆盖就是,对于有点权的有向图,选出权值和最少的点的集合覆盖所有的边. 解二分图最小点权覆盖集可以用最小割: vs-X-Y-vt这样连边,vs和X部点的连边容量为X部点的权值,Y部和vt连边容量 ...
- POJ.2763 Housewife Wind ( 边权树链剖分 线段树维护区间和 )
POJ.2763 Housewife Wind ( 边权树链剖分 线段树维护区间和 ) 题意分析 给出n个点,m个询问,和当前位置pos. 先给出n-1条边,u->v以及边权w. 然后有m个询问 ...
- HDU1565 方格取数(1) —— 状压DP or 插头DP(轮廓线更新) or 二分图点带权最大独立集(最小割最大流)
题目链接:https://vjudge.net/problem/HDU-1565 方格取数(1) Time Limit: 10000/5000 MS (Java/Others) Memory L ...
- poj 3308 Paratroopers(二分图最小点权覆盖)
Paratroopers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8954 Accepted: 2702 Desc ...
随机推荐
- [BZOJ] 1520: [POI2006]Szk-Schools
费用流解决. abs内传不了int..CE一次 #include<iostream> #include<cstring> #include<cstdio> #inc ...
- codis 配置
#修改dashboard.toml: coordinator_name = "zookeeper" coordinator_addr = "192.168.56.101: ...
- python3 兔子繁殖问题
题目 有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少? 代码: month = int(input("繁殖 ...
- 浅谈内核的Makefile、Kconfig和.config文件
Linux内核源码文件繁多,搞不清Makefile.Kconfig..config间的关系,不了解内核编译体系,编译修改内核有问题无从下手,自己写的驱动不知道怎么编进内核,不知道怎么配置内核,这些问题 ...
- $ cat /usr/share/doc/wireshark-common/README.Debian
$ cat /usr/share/doc/wireshark-common/README.Debian I. Capturing packets with Wireshark/Tshark There ...
- IE6 单文件绿色版
IE6单文件绿色版,可以直接运行,无需安装,完美兼容Win10(自带2016年1月更新). https://www.lanzous.com/i3w7dej
- python-高级编程-01
[1] 列表推导 问题 我们需要一个[2,4,6,8] 这样的列表 传统写法 res = [] for i in range(10): if i %2 == 0:res.append(i) print ...
- Emacs 安装与体验
Emacs 安装与体验 下载与安装 首先是下载最新的x64版本的Emacs. 将下载下来的文件解压到你喜欢的磁盘目录下,我选择的是C:\Program Files.放在D盘可能是更好的选择,因 ...
- Thanks for your encourage!
将近三个月的学习,我的努力换回了代表荣誉的小黄衫,这令我很开心啊...我想是不是要写点什么来表达自己的心情呢=,= 于是就有了以下文字ahhhhhh... 学习心得: (1)学习中总会有失败和成功, ...
- [笔记]Docker解决了什么问题?
Docker的优势: 环境依赖问题 更轻量的虚拟化,节省了虚拟机的性能损耗 Docker应用场景: 程序分发,gitlab的安装很恶心吧,所以有人做了gitlab的image 部署发布,这点对运维的同 ...