Paratroopers
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 8837   Accepted: 2663

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

首先用log化×为+,然后源点S向每一行连边,容量是log10(r[i]),每一列向T连边,容量是log10(c[i]),
然后对于每个attacker,把其对应的行列连起来,容量是INF,跑最大流就可以了。 马虎的错误
T和样例个数的T又重了,memset(head)忘掉 然后INF不能开大,开的大一点就WA,同时判断增路的时候要用fabs判断
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=;
const int M=;
const double INF=10.0;
int head[N],tot,S,T;
int q[N],dis[N],n,m,Q;
bool vis[N];
struct node
{
int next,v;
double w;
} e[M<<];
void add(int u,int v,double w)
{
e[tot].v=v;
e[tot].w=w;
e[tot].next=head[u];
head[u]=tot++;
}
bool bfs()
{
memset(dis,-,sizeof(dis));
dis[S]=;
int l=,r=;
q[r++]=S;
while(l<r)
{
int u=q[l++];
for(int i=head[u]; ~i; i=e[i].next)
{
int v=e[i].v;
if(dis[v]==-&&fabs(e[i].w-)>1e-)
{
q[r++]=v;
dis[v]=dis[u]+;
if(v==T) return true;
}
}
}
return false;
}
double dfs(int s,double low)
{
if(s==T||!low) return low;
double ans=low,a;
for(int i=head[s]; ~i; i=e[i].next)
{
if(fabs(e[i].w-)>1e-&&dis[e[i].v]==dis[s]+&&(a=dfs(e[i].v,min(e[i].w,ans))))
{
e[i].w-=a;
e[i^].w+=a;
ans-=a;
if(fabs(ans-)<1e-) return low;
}
}
if(low==ans) dis[s]=-;
return low-ans;
}
int main(){
int Ta,r,c;
for(scanf("%d",&Ta);Ta--;){
scanf("%d%d%d",&n,&m,&Q);
S=,T=n+m+;
memset(head,-,sizeof(head));
tot=;
double x;
for(int i=;i<=n;++i) {
scanf("%lf",&x);
add(S,i,log10(x));
add(i,S,);
}
for(int i=;i<=m;++i) {
scanf("%lf",&x);
add(i+n,T,log10(x));
add(T,i+n,);
}
while(Q--){
scanf("%d%d",&r,&c);
add(r,c+n,INF);
add(c+n,r,);
}
double ans=;
while(bfs()) ans+=dfs(S,INF);
printf("%.4f\n",pow(,ans));
}
}

poj3308 最小点权覆盖的更多相关文章

  1. POJ3308 Paratroopers(最小割/二分图最小点权覆盖)

    把入侵者看作边,每一行每一列都是点,选取某一行某一列都有费用,这样问题就是选总权最小的点集覆盖所有边,就是最小点权覆盖. 此外,题目的总花费是所有费用的乘积,这时有个技巧,就是取对数,把乘法变为加法运 ...

  2. poj3308 Paratroopers --- 最小点权覆盖-&gt;最小割

    题目是一个非常明显的二分图带权匹配模型, 加入源点到nx建边,ny到汇点建边,(nx.ny)=inf建边.求最小割既得最小点权覆盖. 在本题中因为求的是乘积,所以先所有取log转换为加法,最后再乘方回 ...

  3. POJ 2125 Destroying the Graph 二分图最小点权覆盖

    Destroying The Graph Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8198   Accepted: 2 ...

  4. POJ2125 Destroying The Graph(二分图最小点权覆盖集)

    最小点权覆盖就是,对于有点权的有向图,选出权值和最少的点的集合覆盖所有的边. 解二分图最小点权覆盖集可以用最小割: vs-X-Y-vt这样连边,vs和X部点的连边容量为X部点的权值,Y部和vt连边容量 ...

  5. POJ2125 Destroying The Graph (最小点权覆盖集)(网络流最小割)

                                                          Destroying The Graph Time Limit: 2000MS   Memo ...

  6. POJ 2125 Destroying The Graph (二分图最小点权覆盖集+输出最小割方案)

    题意 有一个图, 两种操作,一种是删除某点的所有出边,一种是删除某点的所有入边,各个点的不同操作分别有一个花费,现在我们想把这个图的边都删除掉,需要的最小花费是多少. 思路 很明显的二分图最小点权覆盖 ...

  7. POJ 3308 Paratroopers (对数转换+最小点权覆盖)

    题意 敌人侵略r*c的地图.为了消灭敌人,可以在某一行或者某一列安置超级大炮.每一个大炮可以瞬间消灭这一行(或者列)的敌人.安装消灭第i行的大炮消费是ri.安装消灭第j行的大炮消费是ci现在有n个敌人 ...

  8. POJ2125 Destroying The Graph 二分图 + 最小点权覆盖 + 最小割

    思路来源:http://blog.csdn.net/lenleaves/article/details/7873441 求最小点权覆盖,同样求一个最小割,但是要求出割去了那些边, 只要用最终的剩余网络 ...

  9. POJ 2125 Destroying The Graph 二分图 最小点权覆盖

    POJ2125 题意简述:给定一个有向图,要通过某些操作删除所有的边,每一次操作可以选择任意一个节点删除由其出发的所有边或者通向它的所有边,两个方向有不同的权值.问最小权值和的解决方案,要输出操作. ...

随机推荐

  1. mysql-管理命令【创建用户、授权、修改密码、删除用户和授权、忘记root密码】

    一.创建用户 命令: CREATE USER 'username'@'host' IDENTIFIED BY 'password'; 关键参数说明: username - 创建登录用户名, host ...

  2. 【集群实战】Rsync试题-异机数据备份解决方案

    企业案例:Rsync上机实战考试题: 某公司有一台Web服务器,里面的数据很重要,但是如果硬盘坏了,数据就会丢失,现在领导要求你把数据在其它机器上做一个周期性定时备份. 要求如下: 每天晚上00点整在 ...

  3. 【三剑客】awk函数

    1. 内置函数 awk的内置函数有算术.字符串.时间.位操作和其它杂项的函数. 1.1 算术函数 atan2(y,x)  返回弧度的反正切(y/x) cos(expr)  返回expr的余弦(以弧度形 ...

  4. 第 43 章 Baidu Map

    43.1. BMap.Circle var point = new BMap.Point(22.111, 114.111); var styleCircleF = { strokeColor:&quo ...

  5. linux多线程同步的四种方式

    1. 在并发情况下,指令执行的先后顺序由内核决定.同一个线程内部,指令按照先后顺序执行,但不同线程之间的指令很难说清楚是哪一个先执行.如果运行的结果依赖于多线程执行的顺序,那么就会形成竞争条件,每次运 ...

  6. pycharm 新建文件后选错文件格式怎么改

    经常在新建文件的时候,忘记填写文件后缀,导致文件无默认格式,而且同名字的文件怎么改都改不成想要的格式,所以随手记录一下怎么修正: 原因:肯定是pycharm已经默认指定了一个格式,所以再重复新建同样名 ...

  7. centos7 安装高版本svn

    一.安装高版本svn 1.创建一个新的yum库文件,vim /etc/yum.repos.d/wandisco-svn.repo 内容如下 [WandiscoSVN] name=Wandisco SV ...

  8. Shell脚本(三)重定向

    先上一张图: 代码如下: #!/bin/bash echo "hello world" echo `ls +` 运行结果如下: PS: 1. 如果想同时将数据重定向到文件和stdo ...

  9. 如何使用Golang实现一个API网关

    你是否也存在过这样的需求,想要公开一个接口到网络上.但是还得加点权限,否则被人乱调用就不好了.这个权限验证的过程,最好越简单越好,可能只是对比两个字符串相等就够了.一般情况下我们遇到这种需要,就是在函 ...

  10. Minimum Euler Cycle(找规律+模拟)

    \(给你一个nnn个结点的完全有向图,求其字典序最小的欧拉回路,输出lll到rrr之间的结点为多少.\) 模拟一下n=5的时候 开始肯定是1-2-1-3-1-4-1-5 注意这个时候不能再从5到1,否 ...