POJ 3308 Paratroopers(最小点权覆盖)(对数乘转加)
http://poj.org/problem?id=3308
r*c的地图
每一个大炮可以消灭一行一列的敌人
安装消灭第i行的大炮花费是ri
安装消灭第j行的大炮花费是ci
已知敌人坐标,同时消灭所有敌人,问最小花费
花费为所有大炮消费的乘积
乘转加:log(a*b*c)=log(a)+log(b)+log(c)
经典的最小点权覆盖
源点向行连,列向汇点连
第i行j列有敌人,点i向点j连inf边
最小点权覆盖=最小割
#include<cmath>
#include<queue>
#include<cstdio>
#include<cstring>
#include<algorithm> using namespace std; const double inf=;
const double eps=1e-; #define N 201
#define M 701 int src,decc; int tot;
int front[N],to[M<<],nxt[M<<];
double val[M<<]; int cur[N],lev[N]; queue<int>q; void add(int u,int v,double cap)
{
to[++tot]=v; nxt[tot]=front[u]; front[u]=tot; val[tot]=cap;
to[++tot]=u; nxt[tot]=front[v]; front[v]=tot; val[tot]=;
} bool bfs()
{
for(int i=;i<=decc;++i) lev[i]=-,cur[i]=front[i];
while(!q.empty()) q.pop();
lev[src]=;
q.push(src);
int now,t;
while(!q.empty())
{
now=q.front();
q.pop();
for(int i=front[now];i;i=nxt[i])
{
t=to[i];
if(lev[t]==- && val[i]>eps)
{
lev[t]=lev[now]+;
if(t==decc) return true;
q.push(t);
}
}
}
return false;
} double dinic(int now,double flow)
{
if(now==decc) return flow;
double rest=,delta;
int t;
for(int &i=cur[now];i;i=nxt[i])
{
t=to[i];
if(lev[t]>lev[now] && val[i]>eps)
{
delta=dinic(t,min(flow-rest,val[i]));
if(delta>eps)
{
rest+=delta;
val[i]-=delta; val[i^]+=delta;
if(fabs(rest-flow)<eps) break;
}
}
}
if(fabs(rest-flow)>eps) lev[now]=-;
return rest;
} int main()
{
int T;
scanf("%d",&T);
int n,m,k;
double x,ans;
int a,b;
while(T--)
{
scanf("%d%d%d",&n,&m,&k);
decc=n+m+;
tot=;
memset(front,,sizeof(front));
for(int i=;i<=n;++i)
{
scanf("%lf",&x);
add(src,i,log(x));
}
for(int i=;i<=m;++i)
{
scanf("%lf",&x);
add(i+n,decc,log(x));
}
for(int i=;i<=k;++i)
{
scanf("%d%d",&a,&b);
add(a,b+n,inf);
}
ans=;
while(bfs()) ans+=dinic(src,inf);
printf("%.4lf\n",exp(ans));
}
}
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 8903 | Accepted: 2679 |
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
POJ 3308 Paratroopers(最小点权覆盖)(对数乘转加)的更多相关文章
- POJ - 3308 Paratroopers (最小点权覆盖)
题意:N*M个格点,K个位置会有敌人.每行每列都有一门炮,能打掉这一行(列)上所有的敌人.每门炮都有其使用价值.总花费是所有使用炮的权值的乘积.求最小的总花费. 若每门炮的权值都是1,就是求最小点覆盖 ...
- poj3308 Paratroopers --- 最小点权覆盖->最小割
题目是一个非常明显的二分图带权匹配模型, 加入源点到nx建边,ny到汇点建边,(nx.ny)=inf建边.求最小割既得最小点权覆盖. 在本题中因为求的是乘积,所以先所有取log转换为加法,最后再乘方回 ...
- 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 ...
- zoj 2874 & poj 3308 Paratroopers (最小割)
意甲冠军: 一m*n该网络的规模格.详细地点称为伞兵着陆(行和列). 现在,在一排(或列) 安装激光枪,激光枪可以杀死线(或塔)所有伞兵.在第一i安装一排 费用是Ri.在第i列安装的费用是Ci. 要安 ...
- POJ 3308 Paratroopers (对数转换+最小点权覆盖)
题意 敌人侵略r*c的地图.为了消灭敌人,可以在某一行或者某一列安置超级大炮.每一个大炮可以瞬间消灭这一行(或者列)的敌人.安装消灭第i行的大炮消费是ri.安装消灭第j行的大炮消费是ci现在有n个敌人 ...
- POJ 3308 Paratroopers(最大流最小割の最小点权覆盖)
Description It is year 2500 A.D. and there is a terrible war between the forces of the Earth and the ...
- poj 3308 Paratroopers(二分图最小点权覆盖)
Paratroopers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8954 Accepted: 2702 Desc ...
- poj 3308(最小点权覆盖、最小割)
题目链接:http://poj.org/problem?id=3308 思路:裸的最小点权覆盖,建立超级源点和超级汇点,将源点与行相连,容量为这行消灭敌人的代价,将列与汇点相连,容量为这列消灭敌人的代 ...
- POJ3308 Paratroopers(最小割/二分图最小点权覆盖)
把入侵者看作边,每一行每一列都是点,选取某一行某一列都有费用,这样问题就是选总权最小的点集覆盖所有边,就是最小点权覆盖. 此外,题目的总花费是所有费用的乘积,这时有个技巧,就是取对数,把乘法变为加法运 ...
随机推荐
- 作业45//Calculator::3.0
计算器 github 我的天我到底要写什么 一,2.0及2.6的改动 做了计算部分 加入了判断输入是否合法 合法的定义是算式符合`数字+运算符+数字+运算符+数字`的格式 其中`"-&quo ...
- [usaco]2013-jan Liars and Truth Tellers 真假奶牛
Description 约翰有N头奶牛,有一部分奶牛是真话奶牛,它们只说真话,而剩下的是假话奶牛,只说假话.有一天,约翰从奶牛的闲谈中陆续得到了M句话,第i句话出自第Xi头奶牛,它会告诉约翰第Yi头是 ...
- POJ2823(单调队列方法解题)
因为不太好复制,我就直接截图了,题目链接:题目大致的意思是:给一串数字,然后要你求出每k长度的连续子序列中的最大值以及最小值并输出:这题就是一个最简单的运用单调队列方法解题的例子. 解题思路:通过单调 ...
- 【OSG】将显示的图形窗口化
窗口化原理 有时为了方便控制场景渲染,需要设置一个合适的图形环境窗口(即窗口化). 创建图形环境的主要步骤如下: (1)通过WindowingSystemInterface类得到系统窗口接口,该系统接 ...
- /etc/tolmcat/Server.xml 实例说明
# 这是service类 <Service name="Catalina"> # 这是http连接器,响应用户请求 <Connector port=&qu ...
- Alpha阶段敏捷冲刺①Scrum 冲刺博客
第 1 篇 Scrum 冲刺博客对整个冲刺阶段起到领航作用,应该主要包含三个部分的内容: 各个成员在 Alpha 阶段认领的任务 成员 任务 张晨晨 完成界面设计(前端) 黄登峰 完成界面设计(前端) ...
- https 的理解
前言: 本篇博文来记录下对http及https的理解.(会有点 杂,补缺补漏) 引用:https://blog.csdn.net/u011109589/article/details/80306479 ...
- 『编程题全队』Alpha 阶段冲刺博客Day4
1.每日站立式会议 1.会议照片 2.昨天已完成的工作统计 孙志威: 1.添加团队界面下的看板容器SlotWidget 2.实现SlotWidgets的动态布局管理 3.实现团队/个人界面之间的切换 ...
- 第九周(11.11-11.17)----Beta版本视频发布
beta阶段视频发布地址: http://v.youku.com/v_show/id_XMTgxNjE2NzY3Mg==.html
- JMeter性能测试基础 (2) - 变量的使用
在使用JMeter进行性能测试时,一般情况下要保证样本容量尽可能大,这样才能得到一个比较合理的结果.也就是说,我们不能只对同一个URL进行多次访问,而是要对统一模块下尽可能多的URL进行访问,以取得相 ...