题目链接

题意 : 有一个n*m的矩阵,L个伞兵可能落在某些点上,这些点的坐标已知,需要在某些位置安上一些枪,然后每个枪可以将一行或者一列的伞兵击毙。把这种枪安装到不同行的行首、或者不同列的列首,费用都不同。现在已知把激光枪安装到任意位置的费用,总的花费为这些安装了激光枪的行列花费的乘积。

思路 :就是一个最大流问题。Dinic我不会,用的白皮书上的EK算法,嗯,还行,这个建图比较麻烦,就是把行列分开,成为m+n+1个点。嗯,不废话了,还是把大神博客链接弄过来吧,各方面都讲得很详细。

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <math.h> using namespace std; const int maxn = ;
const int INF = ;
double a[maxn],cap[maxn][maxn],flow[maxn][maxn] ;
double f ;
int p[maxn] ;
int m,n,l; void EK(int s)
{
queue<int>Q ;
memset(flow,,sizeof(flow)) ;
f = ;
for( ; ; )
{
memset(p,-,sizeof(p)) ;
memset(a,,sizeof(a)) ;
a[s] = INF ;
Q.push(s) ;
while(!Q.empty())
{
int u = Q.front() ;Q.pop() ;
for(int v = ; v <= m+n+ ; v++)
{
if(!a[v] && cap[u][v] > flow[u][v])
{
p[v] = u ;
Q.push(v) ;
a[v] = min(a[u],cap[u][v]-flow[u][v]) ;
}
}
}
if(a[m+n+] == ) break ;
for(int u = m+n+ ; u != ; u = p[u])
{
flow[p[u]][u] += a[m+n+] ;
flow[u][p[u]] -= a[m+n+] ;
}
f += a[m+n+] ;
}
}
int main()
{
int T;
scanf("%d",&T) ;
while(T--)
{
memset(cap,,sizeof(cap)) ;
f = ;
double s ;
int x,y ;
scanf("%d %d %d",&m,&n,&l) ;
for(int i = ; i <= m ; i++)
{
scanf("%lf",&s) ;
cap[][i] = log(s) ;
}
for(int i = m+ ; i <= m+n ; i++)
{
scanf("%lf",&s) ;
cap[i][m+n+] = log(s) ;
}
for(int i = ; i < l ; i++)
{
scanf("%d %d",&x,&y) ;
cap[x][m+y] = INF ;
}
EK() ;
printf("%.4f\n",exp(f)) ;
}
return ;
}

POJ 3308 Paratroopers(最小割EK)的更多相关文章

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

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

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

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

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

  4. POJ - 3308 Paratroopers(最大流)

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

  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(最小点权覆盖)(对数乘转加)

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

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

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

  8. Paratroopers(最小割模型)

    http://poj.org/problem?id=3308 题意:一个m*n的网格,有L位火星空降兵降落在网格中,地球卫士为了能同时消灭他们,在网格的行或列安装了一个枪支,每行或每列的枪支都能消灭这 ...

  9. poj 3084(最小割)

    题目链接:http://poj.org/problem?id=3084 思路:题目的意思是不让入侵者进入保护的房间,至少需要锁几道门.网络流建模:设一个超级源点,源点与有入侵者的房间相连,边容量为in ...

  10. poj 1815(最小割、割集)

    题目链接:http://poj.org/problem?id=1815 思路:题目要求是剔除多少个点,可以将其转化为剔除多少条边,因此需要拆点,将点i拆成i,i+n,便容量为1,表示每个人起的传递作用 ...

随机推荐

  1. MySQL高可用解决方案(MySQL HA Solution)

    http://blog.sina.com.cn/s/blog_7e89c3f501012vtr.html 什么是高可用性?很多公司的服务都是24小时*365天不间断的.比如Call Center.这就 ...

  2. system.badimageformatexception 未能加载文件或程序集

    今天在调用dll文件的时候发现这样一个错误.      system.badimageformatexception 未能加载文件或程序集.   发现项目CPU默认Any CPU,我的系统是X64,将 ...

  3. 查看源代码查找获取sd卡剩余容量的代码

    下载android源码,找到app下的Settings应用源码,导入Settings项目(android项目源码) 查找“可用空间”得到 <string name="memory_av ...

  4. Java算法求最大最小值,冒泡排序,斐波纳契数列一些经典算法<不断更新中>

    清明在家,无聊,把一些经典的算法总结了一下. 一.求最大,最小值 Scanner input=new Scanner(System.in); int[] a={21,31,4,2,766,345,2, ...

  5. PHP执行过程

    PHP执行过程     任何一种语言的源代码计算机都没有办法直接执行,需要转换成计算机能够识别的机器指令. PHP也是一门高级语言,也需编译(解释) PHP的解析过程: 1.请求源代码,进行词法解析, ...

  6. Wix: Using Patch Creation Properties - Minor Update

    Based on the project created in Wix: Using Patch Creation Properties - Small Update, Following chang ...

  7. ExecutorService 接口

    先看一个Executor接口,该接口只有一个方法:void execute(Runnable command),用于在未来某个时刻提交一个command,这个command可以被提交到一个新的线程,或 ...

  8. ubuntu12.10可用更新源

    ubutnu12.10自带的更新源已经失效,国内各大服务器的更新源,无论是网易.搜狐还是教育网的因此也失效了.附件是ubuntu12.10目前的可用更新源. 将地址中的“us.archive”换成“o ...

  9. ubuntu12修改ulimit

    第一步:配置/etc/security/limits.confsudo vim /etc/security/limits.conf文件尾追加 * hard nofile 40960* soft nof ...

  10. leetcode problem 42 -- Trapping Rain Water

    Given n non-negative integers representing an elevation map where the width of each bar is 1, comput ...