POJ---3308-Paratroopers(最大流)
2015-12-03 18:30
393 查看
F - Paratroopers
Crawling in process...
Crawling failed
Time Limit:1000MS
Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
Submit
Status
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
Sample Output
Crawling in process...
Crawling failed
Time Limit:1000MS
Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
Submit
Status
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
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <iostream>
#include <algorithm>
#define min_def(x,y) x<y?x:y
using namespace std;
const int N = 105;
const double MAX = 1000000.0;
struct Edge{
int a,b,next;
double val;
} edge[15*N];
int head_edge;
int head
;
int deep
;
int first,end;
void addedge(int a,int b,double val){
edge[head_edge].a=a;
edge[head_edge].b=b;
edge[head_edge].val=val;
edge[head_edge].next=head[a];
head[a]=head_edge++;
edge[head_edge].a=b;
edge[head_edge].b=a;
edge[head_edge].val=0.0;
edge[head_edge].next=head[b];
head[b]=head_edge++;
}
int BFS(){
// cout<<first<<'\12';
queue <int> lll;
memset(deep,-1,sizeof(deep));
deep[first]=0;
lll.push(first);
while(!lll.empty()){
int now=lll.front();
lll.pop();
for(int i=head[now]; i!=-1; i=edge[i].next)
{
int poi=edge[i].b;
if(deep[poi]==-1 && edge[i].val>0)
{
// cout<<poi<<"\n";
deep[poi]=deep[now]+1;
lll.push(poi);
}
}
}
// cout<<end<<" "<<deep[end]<<'\12';
//getchar();
return deep[end] != -1;
}
double dfs(int star,double V){
double r=0;
if(star==end)return V;
for(int i=head[star]; i!=-1 && r<V; i=edge[i].next){
int poi=edge[i].b;
if(edge[i].val>0 && deep[poi]==deep[star]+1){
double x=min(edge[i].val, V-r);
x=dfs(poi,x);
r+=x;
edge[i].val -=x;
edge[i^1].val +=x;
}
}
if(!r)deep[star]=-2;
return r;
}
double dinic(){
double total=0.0,t;
int i=0;
while(BFS()){
while(t=dfs(first,MAX))
total+=t;
//cout<<i++<<'\12';
}
return total;
}
int main(){
int T,i,n,m,k;
double v;
scanf("%d",&T);
while(T--){
head_edge=0;
memset(head,-1,sizeof(head));
memset(deep,-1,sizeof(deep));
scanf("%d%d%d",&n,&m,&k);
first=0;
end=m+n+1;
for(i=1; i<=n; ++i){
scanf("%lf",&v);
addedge(0,i,log(v));
}
for(i=1; i<=m; ++i){
scanf("%lf",&v);
addedge(i+n,end,log(v));
}
int aa,bb;
for(i=1; i<=k; ++i){
scanf("%d%d",&aa,&bb);
addedge(aa,n+bb,MAX);
// cout<<"this\n";
}
double ans=dinic();
printf("%.4lf\n",exp(ans));
}
return 0;
}
/*
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
*/
相关文章推荐
- CentOS系统在不重启的情况下为虚拟机添加新硬盘
- php网站多语言
- Centos下python安装 MySQLdb报错
- 小红帽5.9 配置静态IP上网问题
- CentOS ZooKeeper install
- linux下载jdk
- Linux学习笔记(八、命令搜索命令)
- Ubuntu源码安装Openstack(三)
- 迅为iTOP-4412开发板Ubuntu操作系统烧写方法
- How can I install mySQL on CentOS without being root/su?
- 使用dos指令快速导出手机文件
- Linux学习之创建子进程
- 创建自己的CA机构 - openssl cert 双向认证
- 使用OpenSSL生成证书
- Linux安装jdk
- 【django】Nginx+uWSGI+Django部署我的博客网站
- selenium自动化测试实现对网站的登陆(使用java编写)
- samba configure on Cent OS 6.4
- 告警信息大爆炸,运维解放秘籍!
- 工作常用Linux命令