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

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

这道题第一眼还以为是最优匹配,但是可能开枪数大于最大匹配数,所以不能这么解
以花费为两边容量建边,中间原来的边设为inf,那么每一条边都会流过行花费或者列花费的流量限制
值得一提的是乘积应当转化为自然对数加和然后再指数回来,一开始没看到 另 会在减的过程中小于0,所以直接用a==0判断会T或者WA
//996k 16ms
#include <cstdio>
#include <cstring>
#include <queue>
#include <assert.h>
#include <cmath>
using namespace std;
const double inf=1e20;
const double eps=1e-8;
const int maxnum=302;
const int sups=300,supt=301;
double f[maxnum][maxnum];
int e[maxnum][maxnum];
int len[maxnum]; double min(double a1,double b1) {
return a1<b1?a1:b1;
} int m,n,l;//m ri n ci
void input(){
scanf("%d%d%d",&m,&n,&l);
memset(len,0,sizeof(len)); for(int i=0;i<m;i++){
double ttc;
scanf("%lf",&ttc);
f[sups][i]=log(ttc);
f[i][sups]=0;
e[sups][len[sups]++]=i;
e[i][len[i]++]=sups;
}
for(int i=m;i<m+n;i++){
double ttc;
scanf("%lf",&ttc);
f[i][supt]=log(ttc);
f[supt][i]=0;
e[supt][len[supt]++]=i;
e[i][len[i]++]=supt;
}
for(int i=0;i<l;i++){
int tr,tc;
scanf("%d%d",&tr,&tc);tr--;tc=tc-1+m;
f[tr][tc]=inf;
f[tc][tr]=0;
e[tr][len[tr]++]=tc;e[tc][len[tc]++]=tr;
}
} int d[maxnum];
bool vis[maxnum];
bool bfs(){
memset(vis,0,sizeof(vis));
d[supt]=0;
queue<int >que;
que.push(supt);
vis[supt]=true;
while(!que.empty()){
int fr=que.front();que.pop();
for(int i=0;i<len[fr];i++){
int to=e[fr][i];
if(!vis[to]&&fabs(f[to][fr])>eps){
vis[to]=true;
d[to]=d[fr]+1;
que.push(to);
}
}
}
return vis[sups];
} int cur[maxnum];
double dfs(int s,double a){
if(s==supt||a<eps)return a;
double flow=0;
for(int &i=cur[s];i<len[s];i++){
int to=e[s][i];
double sub;
if(d[s]==d[to]+1&&(sub=dfs(to,min(a,f[s][to])))>eps){
f[s][to]-=sub;
f[to][s]+=sub;
flow+=sub;
a-=sub;
if(fabs(a)<eps)break;
}
}
return flow;
}
double maxflow(){
double ans=0.000;
while(bfs()){
memset(cur,0,sizeof(cur));
ans+=dfs(sups,inf);
}
return ans;
} int main(){
int t;
scanf("%d",&t);
while(t--){
input();
double ans=maxflow();
printf("%.4f\n",exp(ans));
}
return 0;
}

  

												

POJ 3308 Paratroopers 最大流,乘积化和 难度:2的更多相关文章

  1. POJ - 3308 Paratroopers(最大流)

    1.这道题学了个单词,product 还有 乘积 的意思.. 题意就是在一个 m*n的矩阵中,放入L个敌军的伞兵,而我军要在伞兵落地的瞬间将其消灭.现在我军用一种激光枪组建一个防御系统,这种枪可以安装 ...

  2. 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 ...

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

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

  4. POJ - 3308 Paratroopers (最小点权覆盖)

    题意:N*M个格点,K个位置会有敌人.每行每列都有一门炮,能打掉这一行(列)上所有的敌人.每门炮都有其使用价值.总花费是所有使用炮的权值的乘积.求最小的总花费. 若每门炮的权值都是1,就是求最小点覆盖 ...

  5. POJ 3308 Paratroopers(最大流最小割の最小点权覆盖)

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

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

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

  7. poj 3308 Paratroopers

    http://poj.org/problem?id=3308 #include <cstdio> #include <cstring> #include <algorit ...

  8. POJ 3308 Paratroopers(最小割EK)

    题目链接 题意 : 有一个n*m的矩阵,L个伞兵可能落在某些点上,这些点的坐标已知,需要在某些位置安上一些枪,然后每个枪可以将一行或者一列的伞兵击毙.把这种枪安装到不同行的行首.或者不同列的列首,费用 ...

  9. zoj 2874 &amp; poj 3308 Paratroopers (最小割)

    意甲冠军: 一m*n该网络的规模格.详细地点称为伞兵着陆(行和列). 现在,在一排(或列) 安装激光枪,激光枪可以杀死线(或塔)所有伞兵.在第一i安装一排 费用是Ri.在第i列安装的费用是Ci. 要安 ...

随机推荐

  1. poj 3368 Frequent values -Sparse-Table

    Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 16537   Accepted: 5981 Description You ...

  2. ubuntu16.04下编译ceres-solver

    一.编译环境 ubuntu16.04 二.准备工作之安装必要的库 2.1安装cmake sudo apt-get install cmake 2.2 安装google-glog + gflags su ...

  3. gvim写html代码时如何快速地跳转到一个标签的结束位置: 终极插件: matchit.vim

    gvim写html代码时如何快速地跳转到一个标签的结束位置 参考这个vimrc的配置, 里面有一些 很好的东西, 配置很有用, 以前没有用到: http://www.cnblogs.com/wangj ...

  4. JavaScript:正则表达式 问号

    问号 1.?表示重复前面内容的0次或一次(但尽可能多重复) var reg=/abc?/g; var str="abcdabcaba"; console.log(str.match ...

  5. org.apache.shiro.session.InvalidSessionException: java.lang.IllegalStateException: getAttribute: Session already invalidated] with root cause

    1.遇到以下异常,找了好长时间,终于解决,报的异常如下: 七月 07, 2017 3:02:16 下午 org.apache.catalina.core.StandardWrapperValve in ...

  6. 07_Flume_regex interceptor实践

    实践一:regex filter interceptor 1.目标场景 regex filter interceptor的作用: 1)将event body的内容和配置中指定的正则表达式进行匹配2)如 ...

  7. Ajax 随笔

    例子:实现AJAX效果(投票例子) 后端代码 前端代码 原理是使用HTTP状态码204的特性(请求成功,但是不会返回内容,所以浏览器不会进行跳转) 例子:实现AJAX效果(投票例子2) 前端代码 原理 ...

  8. jquery 封装插件

    如今做web开发,jquery 几乎是必不可少的,就连vs神器在2010版本开始将Jquery 及ui 内置web项目里了.至于使用jquery好处这里就不再赘述了,用过的都知道.今天我们来讨论下jq ...

  9. EasyUI ---- draggable购物车

    @{ ViewBag.Title = "Easyui_draggable"; Layout = "~/Views/Shared/Layouts.cshtml"; ...

  10. P2865 【[USACO06NOV]路障Roadblocks】(次短路)

    传送门 算法Dijkstra要求次短路 那么在不考虑重复走一条边的情况下 肯定是把最短路中的一段改成另一段 至少要换另一条边到路径里所以可以枚举所有不属于最短路的每条边(a,b) 那么dis(1,a) ...