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 ...
随机推荐
- java的面向对象 (2013-09-30-163写的日志迁移
1)面向对象的特征 1. 抽象:(从java方面来说抽象大多数人还是把它作为java中的一种特征来对待) 抽象就是忽略一个主题中与当前目标无关的那些方面,以便更充分地注意与当前目标有关的方面.抽象包括 ...
- 如何编写自己的C语言头文件
一些初学C语言的人,不知道头文件(*.h文件)原来还可以自己写的.只知道调用系统库函数时,要使用#include语句将某些头文件包含进去.其实,头文件跟.C文件一样,是可以自己写的.头文件是一种文本文 ...
- NordicSemiconductor.nRF_DeviceFamilyPack 更新历史记录
Version: 8.17.0 (2018-04-27) NordicSemiconductor.nRF_DeviceFamilyPack.8.17.0.packDownload For nRF528 ...
- poj 3616 奶牛产奶问题 dp算法
题意:奶牛产奶,农夫有m个时间段可以挤奶,在工作时间 f t 内产奶量为m,每次挤完奶后,奶牛需要休息R.问:怎么安排使得产奶量最大? 思路:区间dp dp[i]表示第i个时段 对农夫工作的结束时间 ...
- private virtual in c++
source from http://blog.csdn.net/steedhorse/article/details/333664 // Test.cpp #include <iostream ...
- Python学习-day9 线程
这节内容主要是关于线程的学习 首先要了解的什么是进程,什么是线程 进程与线程 什么是进程(process)? 程序并不能单独运行,只有将程序装载到内存中,系统为它分配资源才能运行,而这种执行的程序就称 ...
- NVIDIA NVML Driver/library version mismatch
sudo rmmod nvidia_drm sudo rmmod nvidia_modeset sudo rmmod nvidia_uvm sudo lsof /dev/nvidia* confirm ...
- Codeforces Round #410 (Div. 2) B. Mike and strings
B. Mike and strings time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- javascript基础2 判断 数据类型
js中的数据类型: ------------------------------------------------------------------------------- 返回undefine ...
- DS博客作业05——树
1.本周学习总结 1.1思维导图 1.2学习体会 学习:相比于之前的数据结构,树多了很多性质,相应的也多了很多计算题,不得不说,专有名词也是颇多.觉得树最独特的地方就是它的兄弟.孩子结点,用以组成了它 ...