poj 3308 Paratroopers(二分图最小点权覆盖)
Paratroopers
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 8954 | Accepted: 2702 | 
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
二分图的最小点权覆盖。
code
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath> using namespace std; const int N = ;
const double INF = 1000000000.0;
const double eps = 1e-;
struct Edge{
int to,nxt;double c;
Edge() {}
Edge(int x,double y,int z) {to = x,c = y,nxt = z;}
}e[];
int q[],L,R,S,T,tot = ;
int dis[N],cur[N],head[N]; void add_edge(int u,int v,double c) {
e[++tot] = Edge(v,c,head[u]);head[u] = tot;
e[++tot] = Edge(u,,head[v]);head[v] = tot;
}
bool bfs() {
for (int i=; i<=T; ++i) cur[i] = head[i],dis[i] = -;
L = ,R = ;
q[++R] = S;dis[S] = ;
while (L <= R) {
int u = q[L++];
for (int i=head[u]; i; i=e[i].nxt) {
int v = e[i].to;
if (dis[v] == - && e[i].c > eps) {
dis[v] = dis[u]+;q[++R] = v;
if (v==T) return true;
}
}
}
return false;
}
double dfs(int u,double flow) {
if (u==T) return flow;
double used = ;
for (int &i=cur[u]; i; i=e[i].nxt) {
int v = e[i].to;
if (dis[v] == dis[u] + && e[i].c > eps) {
double tmp = dfs(v,min(flow-used,e[i].c));
if (tmp > eps) {
e[i].c -= tmp;e[i^].c += tmp;
used += tmp;
if (used == flow) break;
}
}
}
if (used != flow) dis[u] = -;
return used;
}
double dinic() {
double ret = 0.0;
while (bfs()) ret += dfs(S,INF);
return ret;
}
void Clear() {
tot = ;
memset(head,,sizeof(head));
}
int main() {
int Case,n,m,E,u,v;double x;
scanf("%d",&Case);
while (Case--) { //-不要设T
Clear();
scanf("%d%d%d",&n,&m,&E);
S = n+m+;T = n+m+;
for (int i=; i<=n; ++i) {
scanf("%lf",&x);
add_edge(S,i,log(x));
}
for (int i=; i<=m; ++i) {
scanf("%lf",&x);
add_edge(i+n,T,log(x));
}
for (int i=; i<=E; ++i) {
scanf("%d%d",&u,&v);
add_edge(u,v+n,INF);
}
double ans = dinic();
printf("%.4lf\n",exp(ans));
}
return ;
}
poj 3308 Paratroopers(二分图最小点权覆盖)的更多相关文章
- POJ 3308 Paratroopers(最小点权覆盖)(对数乘转加)
		
http://poj.org/problem?id=3308 r*c的地图 每一个大炮可以消灭一行一列的敌人 安装消灭第i行的大炮花费是ri 安装消灭第j行的大炮花费是ci 已知敌人坐标,同时消灭所有 ...
 - 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 题意简述:给定一个有向图,要通过某些操作删除所有的边,每一次操作可以选择任意一个节点删除由其出发的所有边或者通向它的所有边,两个方向有不同的权值.问最小权值和的解决方案,要输出操作. ...
 - POJ2125 Destroying The Graph(二分图最小点权覆盖集)
		
最小点权覆盖就是,对于有点权的有向图,选出权值和最少的点的集合覆盖所有的边. 解二分图最小点权覆盖集可以用最小割: vs-X-Y-vt这样连边,vs和X部点的连边容量为X部点的权值,Y部和vt连边容量 ...
 - POJ3308 Paratroopers(最小割/二分图最小点权覆盖)
		
把入侵者看作边,每一行每一列都是点,选取某一行某一列都有费用,这样问题就是选总权最小的点集覆盖所有边,就是最小点权覆盖. 此外,题目的总花费是所有费用的乘积,这时有个技巧,就是取对数,把乘法变为加法运 ...
 - POJ2125 Destroying The Graph 二分图 + 最小点权覆盖 + 最小割
		
思路来源:http://blog.csdn.net/lenleaves/article/details/7873441 求最小点权覆盖,同样求一个最小割,但是要求出割去了那些边, 只要用最终的剩余网络 ...
 - 图论(网络流,二分图最小点权覆盖):POJ 2125 Destroying The Graph
		
Destroying The Graph Description Alice and Bob play the following game. First, Alice draws some di ...
 - POJ  3308 Paratroopers(最小割EK)
		
题目链接 题意 : 有一个n*m的矩阵,L个伞兵可能落在某些点上,这些点的坐标已知,需要在某些位置安上一些枪,然后每个枪可以将一行或者一列的伞兵击毙.把这种枪安装到不同行的行首.或者不同列的列首,费用 ...
 
随机推荐
- 我对USB的认识
			
一.USB协议规范 (1) 基本概念 每一个设备(device)会有一个或者多个的逻辑连接点在里面,每个连接点叫endpoint.每个endpoint有四种数据传送方式:控制(Contr ...
 - 如何配置阿里Maven镜像
			
1.下载maven的zip解压,官方下载地址为:http://maven.apache.org/download.cgi 选择需要下载maven的版本就好了 2.到下载的maven路径下,conf/s ...
 - textArea   默认添加的空格
			
1.会莫名多出一些空格(标签闭合换行了) <textarea class="borderstyle width97b height75" name="SmsTax. ...
 - 解决移动端浏览器页面  X轴横向滚动条问题
			
写web端页面的时候,总是会出现横向滚动条,即 X 轴滚动条,导致页面左右滑来滑去. 即使设置了 body,html {overflow-x:hidden;width:100%;} 也无法生效. 解决 ...
 - VS中生成网站和发布网站的区别
			
VS中生成网站和发布网站的区别 生成网站:是网站项目的编译. 我们知道像一样的C#编译性语言,在运行程序的时候,首先都要经过编译成计算机识别的二进制代码,才能运行.还有网站编译后,浏览 ...
 - C#基础知识图谱
 - django Q条件
			
#q条件from django.db.models import Qq = Q(name__startswith="p") | Q(name__startswith="l ...
 - JSP注释格式
			
一.JSP注释格式来源 JSP是Sun Microsystems公司制定的一种服务器端动态网页技术的组件规范,其主体由HTML.CSS.JavaScript和Java拼凑组成. 正是因为JSP是一种组 ...
 - 域名与IP地址的联系与区别
			
我们也知道每一台机都有一个唯一ip地址, 特别难记,所以出现了今天的DNS(域名) 当我们的计算机想要和一个远程机器连接时,我们可以申请连接该机器ip地址下的DNS,例如:www.baidu.com. ...
 - 获得session中的用户信息
			
由于每个系统都有往session中放入用户信息以及把用户信息取出来的模块,而且在session中取出用户信息的地方非常之多,所以有必要把session中对用户的操作封装成为一个工具类,以便在以后的使用 ...