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. 怎么在java 8的map中使用stream

    怎么在java 8的map中使用stream 简介 Map是java中非常常用的一个集合类型,我们通常也需要去遍历Map去获取某些值,java 8引入了Stream的概念,那么我们怎么在Map中使用S ...

  2. Libra白皮书解读

    文章目录 Libra简介 Libra区块链 Libra货币和存储 Libra协会 Libra简介 Libra是facebook发起的一个区块链项目,其使命是建立一套简单的.无国界的货币和为数十亿人服务 ...

  3. 理解async/await

    async 和 await 在干什么 任意一个名称都是有意义的,先从字面意思来理解.async 是“异步”的简写,而 await 可以认为是 async wait 的简写.所以应该很好理解 async ...

  4. 【深入AQS原理】我画了35张图就是为了让你深入 AQS

    申明 本文首发自公众号:程序员cxuan,此文章为本人投稿文章.已经和cxuan沟通,文章投递公众号,博客平台我自己发布可标记为原创. 此文章肝了很久,图片较多,希望大家喜欢. 另外,感兴趣的小伙伴可 ...

  5. 【集群实战】NFS网络文件共享服务

    1. NFS介绍 1.1 什么是NFS? NFS是Network File System的缩写,中文意思是网络文件系统. 它的主要功能是通过网络(一般是局域网)让不同的主机系统之间可以共享文件或目录. ...

  6. Django项目打包

    Django项目打包 这是目前开发完成的project目录树.我们要打包其中的polls app. (v_python3.6) thinkt@linux-pw37:~/PycharmProjects/ ...

  7. JeeSite 4.0 简化业务逻辑层开发

    2019独角兽企业重金招聘Python工程师标准>>> 引言 对于业务逻辑层的开发重复代码很多,尽管有代码生成器,但从代码量总的来说还是比较多,所以就有了以下抽象类及工具,对一些常用 ...

  8. 在Jetson TX2上显示摄像头视频并使用python进行caffe推理

    参考文章:How to Capture Camera Video and Do Caffe Inferencing with Python on Jetson TX2 与参考文章大部分都是相似的,如果 ...

  9. spark系列-8、Spark Streaming

    参考链接:http://spark.apache.org/docs/latest/streaming-programming-guide.html 一.Spark Streaming 介绍 Spark ...

  10. tomcat多个springboot项目启动失败

    多个springboot项目打包成war包并放到tomcat下运行时出错了错误信息: Caused by: org.springframework.jmx.export.UnableToRegiste ...