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 × 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

题解:

最小点权覆盖,最小割模型,可以用最大流去做,然后就是板子题,重点是转换过程,

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#define inf 0x3f3f
#define ll long long
#define MAXN 30000
using namespace std;
int n,m;//点数、边数
int X[MAXN],y[MAXN];
int sp,tp;//原点、汇点
struct node
{
int v,next;
double cap;
}mp[MAXN*10];
int pre[MAXN],dis[MAXN],cur[MAXN];//cur为当前弧优化,dis存储分层图中每个点的层数(即到原点的最短距离),pre建邻接表
int cnt=0;
void init()//不要忘记初始化
{
cnt=0;
memset(pre,-1,sizeof(pre));
}
void add(int u,int v,double w)//加边
{
mp[cnt].v=v;
mp[cnt].cap=w;
mp[cnt].next=pre[u];
pre[u]=cnt++;
mp[cnt].v=u;
mp[cnt].cap=0;
mp[cnt].next=pre[v];
pre[v]=cnt++;
} bool bfs()//建分层图
{
memset(dis,-1,sizeof(dis));
queue<int>q;
while(!q.empty())
q.pop();
q.push(sp);
dis[sp]=0;
int u,v;
while(!q.empty())
{
u=q.front();
q.pop();
for(int i=pre[u];i!=-1;i=mp[i].next)
{
v=mp[i].v;
if(dis[v]==-1&&mp[i].cap>0)
{
dis[v]=dis[u]+1;
q.push(v);
if(v==tp)
break;
}
}
}
return dis[tp]!=-1;
} double dfs(int u,double cap)//寻找增广路
{
if(u==tp||cap==0)
return cap;
double res=0,f;
for(int i=cur[u];i!=-1;i=mp[i].next)
{
int v=mp[i].v;
if(dis[v]==dis[u]+1&&(f=dfs(v,min(cap-res,mp[i].cap)))>0)
{
mp[i].cap-=f;
mp[i^1].cap+=f;
res+=f;
if(res==cap)
return cap;
}
}
if(!res)
dis[u]=-1;
return res;
} double dinic()
{
double ans=0;
while(bfs())
{
for(int i=0;i<=tp;i++)
cur[i]=pre[i];
ans+=dfs(sp,inf);
}
return ans;
}
int main()
{ int _;
scanf("%d",&_);
int l;
while(_--) {
init();
int len=0;
scanf("%d%d%d",&n,&m,&len);
sp=0;tp=n+m+1;
memset(pre,-1,sizeof pre);
cnt=0;
double w;
for (int i = 1; i <=n ; ++i) {
scanf("%lf",&w);
add(sp,i,log(w));
}
for (int i = 1; i <=m ; ++i) {
scanf("%lf",&w);
add(n+i,tp ,log(w));
}
int a,b;
for (int i = 0; i <len ; ++i) {
scanf("%d%d",&a,&b);
add(a,b+n,inf);
} double kk=dinic();
printf("%.4f\n",exp(kk));
}
return 0;
}

  

poj3308 Paratroopers的更多相关文章

  1. POJ3308 Paratroopers(网络流)(最小割)

                                                     Paratroopers Time Limit: 1000MS   Memory Limit: 655 ...

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

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

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

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

  4. poj3308 Paratroopers 最大流 最小点权覆盖

    题意:有一个n*m的矩阵,告诉了在每一行或者每一列安装大炮的代价,每一个大炮可以瞬间消灭这一行或者这一列的所有敌人,然后告诉了敌人可能出现的L个坐标位置,问如何安置大炮,使花费最小.如果一个敌人位于第 ...

  5. Paratroopers

    Paratroopers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7881 Accepted: 2373 Descript ...

  6. POJ 3308 Paratroopers(最小割EK(邻接表&矩阵))

    Description It is year 2500 A.D. and there is a terrible war between the forces of the Earth and the ...

  7. 伞兵(Paratroopers)

    伞兵(Paratroopers) 时间限制: 1 Sec  内存限制: 128 MB 题目描述 公元 2500 年,地球和火星之间爆发了一场战争.最近,地球军队指挥官获悉火星入侵者将派一些伞兵来摧毁地 ...

  8. POJ 3308 Paratroopers 最大流,乘积化和 难度:2

    Paratroopers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7267   Accepted: 2194 Desc ...

  9. POJ 3308 Paratroopers(最小点权覆盖)(对数乘转加)

    http://poj.org/problem?id=3308 r*c的地图 每一个大炮可以消灭一行一列的敌人 安装消灭第i行的大炮花费是ri 安装消灭第j行的大炮花费是ci 已知敌人坐标,同时消灭所有 ...

随机推荐

  1. 【Spring实战】—— 1 入门讲解

    这个系列是学习spring实战的总结,一方面总结书中所写的精髓,另一方面总结一下自己的感想. 基础部分讲解了spring最为熟知的几个功能:依赖注入/控制反转 和 面向切面编程. 这两个就不再多说了, ...

  2. 用AutoHotkey调整Windows音量

    我用了[右Alt]+方向键来调整音量:Alt+上下键,音量调整幅度为5,如果再增加个右Ctrl,音量调整幅度为1. Alt+左键为静音,Alt+右键为最大音量. >!Up:: ;音量+ < ...

  3. 推荐一个很好用的脚本session snapper

    源网址http://tech.e2sn.com/oracle-scripts-and-tools/session-snapper 内容: If you want to just download Sn ...

  4. Qt 线程初识别

    Qt有两种多线程的方法,其中一种是继承QThread的run函数,另外一种是把一个继承于QObject的类转移到一个Thread里. 这里我使用的是继承的方法使用线程花一个"复杂" ...

  5. NO.010-2018.02.15《上邪》两汉:佚名

    上邪_古诗文网 上邪 两汉:佚名 上邪,我欲与君相知,长命无绝衰.上天呀!我渴望与你相知相惜,长存此心永不褪减.上邪(yé)!:天啊!.上,指天.邪,语气助词,表示感叹. 相知:相爱.命:古与“令”字 ...

  6. linux下时间同步的两种方法分享(转)

    与一个已知的时间服务器同步 代码如下: ntpdate time.nist.gov 其中 time.nist.gov 是一个时间服务器. 删除本地时间并设置时区为上海 复制代码 代码如下: rm -r ...

  7. pocsuite 实现一个verify检测功能

    今天在测试中发现一个命令执行漏洞,尝试用创宇的pocsuite框架实现.说实话,这玩意儿确实没有自己写POC顺手,非得就着他的标准来,就很难受,以至于耽误了很多时间在规范上.. 影响参数后直接用||连 ...

  8. 单独使用JDBC编程

    一.jdbc编程步骤 1. 加载数据库驱动 2. 创建并获取数据库链接 3. 创建jdbc statement对象 4. 设置sql语句 5. 设置sql语句中的参数(使用preparedStatem ...

  9. HTML5之转动的轮子

    <!doctype html><html> <head></head> <body> <canvas width="1000 ...

  10. Openresty最佳案例 | 第9篇:Openresty实现的网关权限控制

    转载请标明出处: http://blog.csdn.net/forezp/article/details/78616779 本文出自方志朋的博客 简介 采用openresty 开发出的api网关有很多 ...