POJ 3308 Paratroopers
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 × ngrid 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
Source
Amirkabir University of Technology Local Contest 2006
二分图最小点权覆盖集
对于一个敌人拆成两个点x,y
从S向x连给定权值的边,
从y向T连给定权值的边,
从x向y连INF的边
二分图最小点权覆盖集=最小割=最大流
乘法取log变加法
mmp精度坑死人
// luogu-judger-enable-o2
#include<cstdio>
#include<cstring>
#include<queue>
#include<cmath>
#define AddEdge(x,y,z) add_edge(x,y,z),add_edge(y,x,0);
using namespace std;
const int MAXN=100001;
double INF=2000000000;
const double eps=1e-9;
int N,M,P,S,T;
struct node
{
int u,v,nxt;
double flow;
}edge[MAXN*5];
int head[MAXN],cur[MAXN],num=0;
inline void add_edge(int x,int y,double z)
{
edge[num].u=x;
edge[num].v=y;
edge[num].flow=z;
edge[num].nxt=head[x];
head[x]=num++;
}
int deep[MAXN];
inline bool BFS()
{
memset(deep,0,sizeof(deep));
deep[S]=1;
queue<int>q;
q.push(S);
while(q.size()!=0)
{
int p=q.front();
q.pop();
for(int i=head[p];i!=-1;i=edge[i].nxt)
if(!deep[edge[i].v]&&edge[i].flow>eps)
{
deep[edge[i].v]=deep[p]+1;q.push(edge[i].v);
if(edge[i].v==T) return 1;
}
}
return deep[T];
}
double DFS(int now,double nowflow)
{
if(now==T||nowflow<eps) return nowflow;
double totflow=0;
for(int &i=cur[now];i!=-1;i=edge[i].nxt)
{
if(deep[edge[i].v]==deep[now]+1&&edge[i].flow>eps)
{
double canflow=DFS(edge[i].v,min(nowflow,edge[i].flow));
if(canflow>eps)
{
edge[i].flow-=canflow;
edge[i^1].flow+=canflow;
totflow+=canflow;
nowflow-=canflow;
}
if(nowflow<eps) break;
}
}
return totflow;
}
double Dinic()
{
double ans=0;
while(BFS())
{
memcpy(cur,head,sizeof(head));
ans+=DFS(S,INF);
}
return ans;
}
double valr,valc;
int main()
{
#ifdef WIN32
freopen("a.in","r",stdin);
#else
#endif
int test;
scanf("%d",&test);
while(test--)
{
memset(head,-1,sizeof(head));
scanf("%d%d%d",&N,&M,&P);S=0;T=N+M+P;
for(int i=1;i<=N;i++) scanf("%lf",&valr),AddEdge(S,i,log(valr) );
for(int i=1;i<=M;i++) scanf("%lf",&valc),AddEdge(i+N,T,log(valc) );
for(int i=1;i<=P;i++)
{
int x,y;
scanf("%d%d",&x,&y);
AddEdge(x,y+N,INF);
}
printf("%.4lfn",exp(Dinic()));
}
return 0;
}
- 这或许是对小白最友好的python入门了吧——20,定义函数简单应用
- 数据库结构版本控制
- Extjs4---Cannot read property 'addCls' of null 或者 el is null 关于tab关闭后再打开不显示或者报错
- 【干货】什么?Python3.X不能输出中文?原来是编辑器geany的锅?!
- Shell 历史记录异地留痕审计与监控
- [译]WebAPI下的如何实现参数绑定
- 这或许是对小白最友好的python入门了吧——10,元组
- Extjs 在项目中碰到问题
- 网站防刷方案
- 如何正确的猜拳:反事实遗憾最小化算法
- 使用python中的Numpy进行t检验
- 实操 Web Cache
- 怎样制作RPM包
- 框架设计原则和规范(完)
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- MySQL千万大表优化实践
- GitHub 标星过万!计算机与网络知识总结电子书下载!
- 盘一盘,那些提效/创意的 vscode 插件
- 基于jenkins实现手动拉取码云代码,实现半自动化部署
- so easy!网页骨架屏自动生成方案(dps)
- 深夜,我偷听到程序员要对session下手……
- CAM 系列论文阅读总结
- kafka客户端指标上报Prometheus方案(已开源)
- 2020-09-25:rust中Point是结构体类型,【let p1=Point{x:25,y:25};let p2=p1;】...
- R语言在BRFSS数据中可视化分析探索糖尿病的影响因素
- R语言可视化探索BRFSS数据并逻辑回归Logistic回归预测中风
- R语言对BRFSS数据探索回归数据分析
- 使用R语言创建自定义桑基图Sankey图
- 在r语言中使用GAM(广义相加模型)进行电力负荷时间序列分析
- R语言中的偏最小二乘回归PLS-DA