博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 3380 最大流
阅读量:4992 次
发布时间:2019-06-12

本文共 4531 字,大约阅读时间需要 15 分钟。

Paratroopers
Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u
     
Appoint description:  System Crawler  (2014-10-14)

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 × 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 npositive 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

14 4 52.0 7.0 5.0 2.01.5 2.0 2.0 8.01 12 23 34 41 4

Sample Output

16.0000

题意:给出火星人降落的坐标(行x,列y)和使用每一行每一列武器的代价,你能够在一行或一列使用一把武器,能够消灭掉该行或该列的全部外星人。使用多种武器的代价是他们的乘积,你须要求出消灭全部火星人的最小代价。

思路:在把乘机转化成对数相加的形式,能够看到要消灭一个外星人,要么在他所在的行上放一把武器,要么在他所在列上放一把武器,因此能够在源点s和行x上连一条log(w)的边,在列和汇点t上连一条log(w)的边,在外星人的坐标x和y+n之间连一条INF的边。由于增广的时候满足流量限制所以会选择最小的代价。

只是还是wa了非常久。。原因就是用个g++提交,输出的时候使用了%lf,后来改成%f了还是wa,后来发现关闭了c++和c的输入输出同步,但任然在混用输入。。取消关闭之后就ac了。。。所以建议没事还是不要混用输入输出了

代码例如以下:

/*************************************************************************    > File Name: c.cpp    > Author: acvcla    > QQ:      > Mail: acvcla@gmail.com     > Created Time: 2014年10月13日 星期一 22时26分17秒 ************************************************************************/#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;typedef long long LL;const int maxn = 5e2 + 30;const int INF =1e7;#define rep(i,a,b) for(int i=(a);i<=(b);i++)#define pb push_backint n,m,s,t,l;int d[maxn],cur[maxn];struct Edge{ int from,to; double cap,flow;};std::vector
G[maxn];std::vector
edges;void init(int n){ for(int i=0;i<=n;i++)G[i].clear(); edges.clear();}void addEdge(int u,int v,double w){ edges.pb((Edge){u,v,w,0}); edges.pb((Edge){v,u,0.0,0}); int sz=edges.size(); G[u].pb(sz-2); G[v].pb(sz-1);}int bfs(){ memset(d,0,sizeof d); queue
q; q.push(s); while(!q.empty()){ int u=q.front();q.pop(); for(int i=0;i
e.flow){ q.push(e.to); d[e.to]=d[u]+1; } } } return d[t];}double dfs(int u,double a){ if(u==t||a==0.0)return a; double flow=0.0,f=0.0; for(int &i=cur[u];i
0.0){ e.flow+=f; edges[G[u][i]^1].flow-=f; flow+=f; a-=f; if(a==0.0)break; } } return flow;}double Dinic(){ double flow=0; while(bfs()){ memset(cur,0,sizeof cur); flow+=dfs(s,INF); } return flow;}int main(){ //开启关闭同步且混用输入输出wa,凝视掉AC //ios_base::sync_with_stdio(false); //cin.tie(0); int T;scanf("%d",&T); while(T--){ scanf("%d%d%d",&n,&m,&l); int u,v; s=0,t=n+1+m; init(t); double w; for(int i=1;i<=n;i++){ cin>>w; addEdge(s,i,log(w)); }for(int i=1;i<=m;i++){ cin>>w; addEdge(n+i,t,log(w)); } for(int i=1;i<=l;i++){ cin>>u>>v; addEdge(u,v+n,INF); } double ans=Dinic(); printf("%.4f\n",exp(ans)); } return 0;}

转载于:https://www.cnblogs.com/mengfanrong/p/4380429.html

你可能感兴趣的文章
【數據結構】哈工大實驗一:一元多项式(代碼以及報告)
查看>>
简单理解Socket
查看>>
Hortonworks HDP Sandbox定制(配置)开机启动服务(组件)
查看>>
DHCP Option 60 认识
查看>>
浅析连续子向量,子数组和(一维,二维)问题
查看>>
C/C++中各种类型int、long、double、char表示范围(最大最小值)
查看>>
Linux环境下Eclipse + Tomcat + MySQL 配置J2EE开发环境的方法
查看>>
机器学习实战:第九章 树回归
查看>>
while(~scanf("%d %d",&a,&b))和while(scanf("%d %d",&a,&b)!=EOF)
查看>>
使用vs code开发纸壳CMS并启用Razor智能提示
查看>>
动态投资回收期Pt小于计算期n
查看>>
Python模拟登入豆瓣网,并爬取小组信息
查看>>
初识Jsp,JavaBean,Servlet以及一个简单mvc模式的登录界面
查看>>
@import与link的区别与选择
查看>>
ORA-14411 该 DDL 不能与其他 DDL 并行运行处理办法
查看>>
C#筛法求出范围内的所有质数
查看>>
程序员常用的几款软件
查看>>
noi2014 起床困难综合症
查看>>
.NET ->> 分享一个字符串模糊匹配指数的方法
查看>>
HDU2907凸包+凹面
查看>>