Paratroopers

时间:2023-01-24 19:35:50

Paratroopers

Time Limit: 1000MS Memory Limit: 65536K

Total Submissions: 7881 Accepted: 2373

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

Source

Amirkabir University of Technology Local Contest 2006

好恶心的题啊,一直超时,后来也没有怎么改经过一大波的TLE后就过了,好奇怪,难道精度没有控制好?

#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std; const double INF = 10000.0; const double eps = 1e-8; const int Max = 3000; struct Edge
{
int v;
int next;
double cap;
}E[Max]; int Head[120];
int Du[120];
int top;
int n,m,L;
int s,t;
void AddEdge(int u,int v,double w)
{
E[top].cap=w;E[top].v=v;
E[top].next=Head[u];Head[u]=top++;
E[top].cap=0;E[top].v=u;
E[top].next=Head[v];Head[v]=top++;
}
double Eps(double s)
{
return fabs(s)<eps?0:s;
}
double min(double a,double b)
{
return a<b?a:b;
}
int bfs()
{
memset(Du,0,sizeof(Du));
queue<int>Q;
Du[s]=1;
Q.push(s);
while(!Q.empty())
{
int a=Q.front();
Q.pop();
for(int i=Head[a];i!=-1;i=E[i].next)
{
if(Du[E[i].v]==0&&Eps(E[i].cap)>0)
{
Du[E[i].v]=Du[a]+1;
Q.push(E[i].v);
}
}
}
return Du[t];
} double dfs(int star,double num)
{ if(star==t)
{
return num;
}
double S=0;
double ant;
for(int i=Head[star];i!=-1;i=E[i].next)
{
if(Du[star]+1==Du[E[i].v]&&Eps(E[i].cap)>0)
{
ant=dfs(E[i].v,min(E[i].cap,num));
E[i].cap-=ant;
E[i^1].cap+=ant;
num-=ant;
S+=ant;
if(Eps(num)==0)
{
break;
}
}
}
return S;
}
double Dinic()
{
double ant=0;
while(bfs())
{
ant+=dfs(0,INF);
}
return ant;
} int main()
{
int T;
double w;
int u,v;
scanf("%d",&T);
while(T--)
{
scanf("%d %d %d",&n,&m,&L);
s=0;
t=n+m+1;
top=0;
memset(Head,-1,sizeof(Head));
for(int i=1;i<=n;i++)
{
scanf("%lf",&w);
AddEdge(s,i,log(w));
}
for(int i=1;i<=m;i++)
{
scanf("%lf",&w);
AddEdge(n+i,t,log(w));
}
for(int i=1;i<=L;i++)
{
scanf("%d %d",&u,&v);
AddEdge(u,v+n,INF);
}
printf("%.4f\n",exp(Dinic()));
}
return 0;
}

Paratroopers的更多相关文章

  1. POJ3308 Paratroopers&lpar;网络流)(最小割)

                                                     Paratroopers Time Limit: 1000MS   Memory Limit: 655 ...

  2. POJ 3308 Paratroopers&lpar;最小割EK(邻接表&amp&semi;矩阵)&rpar;

    Description It is year 2500 A.D. and there is a terrible war between the forces of the Earth and the ...

  3. 伞兵&lpar;Paratroopers&rpar;

    伞兵(Paratroopers) 时间限制: 1 Sec  内存限制: 128 MB 题目描述 公元 2500 年,地球和火星之间爆发了一场战争.最近,地球军队指挥官获悉火星入侵者将派一些伞兵来摧毁地 ...

  4. POJ 3308 Paratroopers 最大流&comma;乘积化和 难度&colon;2

    Paratroopers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7267   Accepted: 2194 Desc ...

  5. POJ 3308 Paratroopers(最小点权覆盖)(对数乘转加)

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

  6. POJ 3308 Paratroopers(最大流最小割の最小点权覆盖)

    Description It is year 2500 A.D. and there is a terrible war between the forces of the Earth and the ...

  7. poj3308 Paratroopers

    Description It is year 2500 A.D. and there is a terrible war between the forces of the Earth and the ...

  8. poj 3308 Paratroopers(二分图最小点权覆盖)

    Paratroopers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8954   Accepted: 2702 Desc ...

  9. POJ - 3308 Paratroopers(最大流)

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

随机推荐

  1. 基于Python的TestAgent实现

    问题: 1.本人工作主要做自动化,经常要去Linux后台进行一些脚本操作,有时要去后台执行命令,如果逐个登陆比较费事,效率会大打折扣 2.虽然有可以直接去后台执行命令的AW,但是该AW存在很多问题,而 ...

  2. Owin SelfHost Asp&period;net WebApi 遇到 No type was found that matches the controller named &&num;39&semi;ControllerName&&num;39&semi; 异常的解决方案

    问题背景:在使用普通的SelfHost时,调用其它工程的dll(其实就是把WebApi写到一个单独的工程方便管理),通过加载其他工程的dll然后再访问webapi是没有问题的. 但是在使用Owin S ...

  3. php session详解

    <?php /* * session_abort — Discard session array changes and finish session 舍弃会话序列变化和结束会话 session ...

  4. linux 通过 ulimit 改善系统性能

    https://www.ibm.com/developerworks/cn/linux/l-cn-ulimit/ 概述 系统性能一直是一个受关注的话题,如何通过最简单的设置来实现最有效的性能调优,如何 ...

  5. hdu 5429&lpar;大数模板&rpar;

    题意:判断是否是等比数列 a[i] * a[i] = a[i+1] * a[i-1]   +   部分为0 的情况 /*  表示还没学java.... ,模板来自NK_test #include &l ...

  6. 仿9GAG制作过程(五)

    有话要说: 在做完了数据展示功能之后,就想着完善整个APP.发现现在后台非常的混乱,有好多点都不具备,比方说:图片应该有略缩图和原图,段子.评论.点赞应该联动起来,段子应该有创建时间等. 于是就重新设 ...

  7. asp&period;net 调用 WNetAddConnection2 window api 访问被拒绝

    通过Asp.net 程序调用局域网另外一台机器文件,显示拒绝访问,单独编写控制台程序正常. 修改iis 应用程序池标识,为管理员用户即可!!

  8. 迷宫问题 dfs bfs 搜索

    定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, ...

  9. 转载:案例用Excel对会员客户交易数据进行RFM分析

    案例:用Excel对会员客户交易数据进行RFM分析                                背景: 一个会员服务的企业,有近1年约1200个会员客户的收银数据.由于公司想针对不同 ...

  10. 树莓派GPIO控制LED彩灯

    树莓派使用GPIO接口来控制LED灯,自制五彩炫光的节日彩灯. 1.硬件准备 a. 树莓派(Raspberry Pi)一个 b. 彩色RGB二极管 c. 杜邦线 d. 5V电源引脚 以上所有零件均可在 ...