POJ3308 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(网络流)(最小割)的更多相关文章
- POJ3308 Paratroopers(最小割/二分图最小点权覆盖)
把入侵者看作边,每一行每一列都是点,选取某一行某一列都有费用,这样问题就是选总权最小的点集覆盖所有边,就是最小点权覆盖. 此外,题目的总花费是所有费用的乘积,这时有个技巧,就是取对数,把乘法变为加法运 ...
- 【题解】 bzoj3894: 文理分科 (网络流/最小割)
bzoj3894,懒得复制题面,戳我戳我 Solution: 首先这是一个网络流,应该还比较好想,主要就是考虑建图了. 我们来分析下题面,因为一个人要么选文科要么选理科,相当于两条流里面割掉一条(怎么 ...
- 【bzoj3774】最优选择 网络流最小割
题目描述 小N手上有一个N*M的方格图,控制某一个点要付出Aij的代价,然后某个点如果被控制了,或者他周围的所有点(上下左右)都被控制了,那么他就算是被选择了的.一个点如果被选择了,那么可以得到Bij ...
- 【bzoj1143】[CTSC2008]祭祀river Floyd+网络流最小割
题目描述 在遥远的东方,有一个神秘的民族,自称Y族.他们世代居住在水面上,奉龙王为神.每逢重大庆典, Y族都会在水面上举办盛大的祭祀活动.我们可以把Y族居住地水系看成一个由岔口和河道组成的网络.每条河 ...
- 【bzoj1797】[Ahoi2009]Mincut 最小割 网络流最小割+Tarjan
题目描述 给定一张图,对于每一条边询问:(1)是否存在割断该边的s-t最小割 (2)是否所有s-t最小割都割断该边 输入 第一行有4个正整数,依次为N,M,s和t.第2行到第(M+1)行每行3个正 整 ...
- 【bzoj1976】[BeiJing2010组队]能量魔方 Cube 网络流最小割
题目描述 一个n*n*n的立方体,每个位置为0或1.有些位置已经确定,还有一些需要待填入.问最后可以得到的 相邻且填入的数不同的点对 的数目最大. 输入 第一行包含一个数N,表示魔方的大小. 接下来 ...
- 【bzoj4177】Mike的农场 网络流最小割
题目描述 Mike有一个农场,这个农场n个牲畜围栏,现在他想在每个牲畜围栏中养一只动物,每只动物可以是牛或羊,并且每个牲畜围栏中的饲养条件都不同,其中第i个牲畜围栏中的动物长大后,每只牛可以卖a[i] ...
- 【bzoj3438】小M的作物 网络流最小割
原文地址:http://www.cnblogs.com/GXZlegend/p/6801522.html 题目描述 小M在MC里开辟了两块巨大的耕地A和B(你可以认为容量是无穷),现在,小P有n中作物 ...
- 【bzoj3144】[Hnoi2013]切糕 网络流最小割
题目描述 输入 第一行是三个正整数P,Q,R,表示切糕的长P. 宽Q.高R.第二行有一个非负整数D,表示光滑性要求.接下来是R个P行Q列的矩阵,第z个 矩阵的第x行第y列是v(x,y,z) (1≤x≤ ...
- 【bzoj3894】文理分科 网络流最小割
原文地址:http://www.cnblogs.com/GXZlegend 题目描述 文理分科是一件很纠结的事情!(虽然看到这个题目的人肯定都没有纠结过) 小P所在的班级要进行文理分科.他的班级可以用 ...
随机推荐
- DOS下快速删除文件
Windows服务器或普通操作系统中经常会遇到很多生成的临时文件需要删除,如果需要删除的文件夹中数目很多,且文件很巨大时,如果通过鼠标选择文件夹再直接删除会响应得非常慢,特别是文件数量也巨大时,Win ...
- 安全增强 Linux (SELinux) 剖析
架构和实现 Linux® 一直被认为是最安全的操作系统之一,但是通过引入安全增强 Linux(Security-Enhanced Linux,SELinux),National Security Ag ...
- 华为V-ISA信誉安全体系:对付新型DDoS攻击的利器
华为Anti-DDoS解决方案基于华为颇具传统优势的专业软硬件平台开发,在防护机制中,引入先进的检测机制,提供了业内首创的“V-ISA”信誉安全体系,是业界唯一单机可提供超百G DDoS防御能 ...
- Ubuntu 14.10 下安装Ganglia监控集群
关于 Ganglia 软件,Ganglia是一个跨平台可扩展的,高性能计算系统下的分布式监控系统,如集群和网格.它是基于分层设计,它使用广泛的技术,如XML数据代表,便携数据传输,RRDtool用于数 ...
- JS 用window.open()函数,父级页面如何取到子级页面的返回值?
父窗口:<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> ...
- 学习:Log中'main', 'system', 'radio', 'events'
在Android中不同的log写到不同的设备中,共有/dev/log/system, /dev/log/main, /dev/log/radion, /dev/log/events四中类型.其中默认L ...
- JQuery事件手册
blur.focus blur失去焦点:focus获得焦点 load 当指定的元素(及子元素)已加载时,会发生 load() 事件 resize 当调整浏览器窗口的大小时,发生 resize ...
- The name 'Scripts' does not exist in the current context error in MVC
创建完成ASP.NET MVC4应用程序以后,试着运行其中一个Create页面, 程序报出运行是错误: CS0103: The name 'Scripts' does not exist in th ...
- 换个心境搞IT,在IT职场如何打拼?
刚进入IT这行时,我也是从程序员做起.尤其是前两三个月里,那种感觉就像时时刻刻处于备战状态一样.我是一个在对自己的要求方面有洁癖的人,在没有任何经验的状态下,只有坚持苦干,把下发的每件编程任务做好,才 ...
- Exploratory Software Testing
最近找到去年上半年看过一本关于测试方面书籍的总结笔记,一直放在我的个人U盘里,当时是用Xmind记录的,现在重新整理下分享给大家了! James A.Whittaker [美] 詹姆斯·惠特克(软件测 ...