Paratroopers
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 8443   Accepted: 2541

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
【分析】讲真,要不是看题解,很难想到用网络流做。这题建图是把每一行,每一列作为结点,然后建立两个
超级源点,汇点,源点与行连边,容量为Ri,列与汇点连边,容量为Ci,对于位置坐标,行向列连边,容量
为inf,然后求最大流。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <time.h>
#include <string>
#include <map>
#include <stack>
#include <vector>
#include <set>
#include <queue>
#define inf 10000000
#define mod 10000
typedef long long ll;
using namespace std;
const int N=;
const int M=;
int power(int a,int b,int c){int ans=;while(b){if(b%==){ans=(ans*a)%c;b--;}b/=;a=a*a%c;}return ans;}
struct man
{
double c,f;
}w[N][N];
int head[N],dis[N],pre[N],n,m,k;
int t,cnt=,maxn;
double ans;
bool flag; bool bfs()
{
queue<int>q;
memset(pre,-,sizeof(pre));
q.push();
pre[]=;
while(!q.empty() && !dis[t]){
int u=q.front();q.pop();
for(int i=;i<=t;i++){
if(pre[i]==-&&w[u][i].c>w[u][i].f){
q.push(i);
pre[i]=u;
if(i==t) return true;
}
}
}
return false;
} void dinic()
{
ans=;
while(bfs()){
double tt=inf;
for(int i=t;i!=;i=pre[i]){
tt=min(tt,w[pre[i]][i].c-w[pre[i]][i].f);
}
for(int i=t;i!=;i=pre[i]){
w[pre[i]][i].f+=tt;w[i][pre[i]].f-=tt;
}
ans+=tt;
}
printf("%.4lf\n",exp(ans));
} void init()
{
int a,b;
double d;
scanf("%d%d%d",&n,&m,&k);t=n+m+;
for(int i=;i<=n;i++){
scanf("%lf",&d);
d=log(d);
w[][i].c=d;
}
for(int i=;i<=m;i++){
scanf("%lf",&d);
d=log(d);
w[i+n][t].c=d;
}
while(k--){
scanf("%d%d",&a,&b);
w[a][b+n].c=inf;
}
} int main(){
int T;
scanf("%d",&T);
while(T--){
memset(w,,sizeof(w));
ans=;
init();
dinic();
}
return ;
}

POJ3308 Paratroopers(网络流)(最小割)的更多相关文章

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

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

  2. 【题解】 bzoj3894: 文理分科 (网络流/最小割)

    bzoj3894,懒得复制题面,戳我戳我 Solution: 首先这是一个网络流,应该还比较好想,主要就是考虑建图了. 我们来分析下题面,因为一个人要么选文科要么选理科,相当于两条流里面割掉一条(怎么 ...

  3. 【bzoj3774】最优选择 网络流最小割

    题目描述 小N手上有一个N*M的方格图,控制某一个点要付出Aij的代价,然后某个点如果被控制了,或者他周围的所有点(上下左右)都被控制了,那么他就算是被选择了的.一个点如果被选择了,那么可以得到Bij ...

  4. 【bzoj1143】[CTSC2008]祭祀river Floyd+网络流最小割

    题目描述 在遥远的东方,有一个神秘的民族,自称Y族.他们世代居住在水面上,奉龙王为神.每逢重大庆典, Y族都会在水面上举办盛大的祭祀活动.我们可以把Y族居住地水系看成一个由岔口和河道组成的网络.每条河 ...

  5. 【bzoj1797】[Ahoi2009]Mincut 最小割 网络流最小割+Tarjan

    题目描述 给定一张图,对于每一条边询问:(1)是否存在割断该边的s-t最小割 (2)是否所有s-t最小割都割断该边 输入 第一行有4个正整数,依次为N,M,s和t.第2行到第(M+1)行每行3个正 整 ...

  6. 【bzoj1976】[BeiJing2010组队]能量魔方 Cube 网络流最小割

    题目描述 一个n*n*n的立方体,每个位置为0或1.有些位置已经确定,还有一些需要待填入.问最后可以得到的 相邻且填入的数不同的点对 的数目最大. 输入 第一行包含一个数N,表示魔方的大小. 接下来 ...

  7. 【bzoj4177】Mike的农场 网络流最小割

    题目描述 Mike有一个农场,这个农场n个牲畜围栏,现在他想在每个牲畜围栏中养一只动物,每只动物可以是牛或羊,并且每个牲畜围栏中的饲养条件都不同,其中第i个牲畜围栏中的动物长大后,每只牛可以卖a[i] ...

  8. 【bzoj3438】小M的作物 网络流最小割

    原文地址:http://www.cnblogs.com/GXZlegend/p/6801522.html 题目描述 小M在MC里开辟了两块巨大的耕地A和B(你可以认为容量是无穷),现在,小P有n中作物 ...

  9. 【bzoj3144】[Hnoi2013]切糕 网络流最小割

    题目描述 输入 第一行是三个正整数P,Q,R,表示切糕的长P. 宽Q.高R.第二行有一个非负整数D,表示光滑性要求.接下来是R个P行Q列的矩阵,第z个 矩阵的第x行第y列是v(x,y,z) (1≤x≤ ...

  10. 【bzoj3894】文理分科 网络流最小割

    原文地址:http://www.cnblogs.com/GXZlegend 题目描述 文理分科是一件很纠结的事情!(虽然看到这个题目的人肯定都没有纠结过) 小P所在的班级要进行文理分科.他的班级可以用 ...

随机推荐

  1. JAVA学习1

    以前学过JAVA,但是长时间不用又给忘了,趁着还有时间回顾一下. 一切皆是对象.

  2. [microsoft]PE和COFF文件格式

    前言 我们知道,vs的C/C++编译工具把每一个编译单元(一个.c或.cpp源文件)编译成一个对象文件(.obj文件):然后用链接器把这些对象文件组合一个单个文件(.exe文件),称为可移植的可执行文 ...

  3. for循环和while循环的区别

    public class Xunhuanqubie { public static void main(String[] args){ int i = 0; while(i<8){ System ...

  4. python版恶俗古风自动生成器.py

    python版恶俗古风自动生成器.py """ python版恶俗古风自动生成器.py 模仿自: http://www.jianshu.com/p/f893291674c ...

  5. SwipeRefreshLayout

    也许之前下拉刷新你可能会用到一些第三方开源库,如PullToRefresh, ActionBar-PullToRefresh.XlistView等 但现在已经有官方的组件了---SwipeRefres ...

  6. hdu 2035

    Ps:查了下快速幂,顺便在这用下.... 积的求余等于两个数的求余的积再求余... 代码: #include "stdio.h"int mod(int a,int b);int m ...

  7. 前端开发者应该知道的 CSS 小技巧

    一些小技巧让你的CSS技术更专业 使用:not()去除导航上不需要的边框 为body添加行高 垂直居中任何元素 逗号分离的列表 使用负nth-child选择元素 使用SVG图标 文本显示优化 在纯CS ...

  8. Tomcat服务绑定域名的方法

    在搭建了tomcat服务器之后,建议将域名绑定到服务器.绑定方法如下:    域名绑定需要编辑tomcat的配置文件完成.tomcat配置文件是TOMCAT_HOME/conf/server.xml, ...

  9. Egret

    http://www.manew.com/forum-html5Engine-1.html http://www.manew.com/forum-html5Engine-1.html https:// ...

  10. Java最近版本新特性使用介绍

    本文来自http://blog.csdn.net/liuxian13183/ ,引用必须注明出处! 在阅读<Thinking in Java>的过程中,并发这一章出现不少新特性,工作中也有 ...