POJ 3308 Paratroopers
2013-05-29 22:43
330 查看
[align=center]Paratroopers[/align]
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
Source
Amirkabir University of Technology Local Contest 2006
考察点:最大流
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 5796 | Accepted: 1707 |
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
考察点:最大流
/*************************************************************** > File Name: paratroopers.cpp > Author: SDUT_GYX > Mail: 2272902662@qq.com > Created Time: 2013/5/29 20:02:52 **************************************************************/ #include <iostream> #include <cstring> #include <algorithm> #include <cstdio> #include <queue> #include <cstdlib> #include <iomanip> #include <string> #include <vector> #include <map> #include <cmath> #include <stack> #define LL long long #define N 1000 #define eqs 1e-8 using namespace std; struct num { double val; int sta,end,pre,next; }col ,row ,a[N*10000]; int pt ,level ,node ,Top,sta,end,sum=0; bool inqueue ; double inf=(double)0x7ffffff; int main() { void addeage(int x,int y,double val,int k); double dinic(); int n,m,k,t; scanf("%d",&t); while(t--) { scanf("%d %d %d",&n,&m,&k); for(int i=0; i<=n-1; i++) { scanf("%lf",&row[i].val); } for(int i=0;i<=m-1; i++) { scanf("%lf",&col[i].val); } memset(pt,-1,sizeof(pt)); Top=0; sta=0; end = n + m + 1; for(int i=1;i<=n; i++) { addeage(0,i,log10(row[i-1].val),1); addeage(i,0,0,-1); } for(int i=1;i<=m;i++) { addeage(n+i,end,log10(col[i-1].val),1); addeage(end,n+i,0,-1); } while(k--) { int x,y; scanf("%d %d",&x,&y); addeage(x,n+y,inf,1); addeage(n+y,x,0,-1); } double res = dinic(); res = pow(10,res); printf("%.4lf\n",res); } return 0; } void addeage(int x,int y,double val,int k) { a[Top].sta = x; a[Top].end = y; a[Top].val = val; a[Top].pre = Top+k; a[Top].next = pt[x]; pt[x] = Top; Top++; } int bfs() { memset(inqueue, false, sizeof(inqueue)); memset(level,-1,sizeof(level)); queue<int> que; que.push(sta); inqueue[sta] = true; level[sta] = 0; while(!que.empty()) { int x=que.front(); que.pop(); for(int i=pt[x]; i!=-1; i=a[i].next) { int y = a[i].end; double val = a[i].val; if(!inqueue[y]&&!(fabs(val - 0.0)<=eqs)) { level[y] = level[x] + 1; que.push(y); inqueue[y] = true; } } } if(level[end] == -1) { return 0; } return 1; } double dfs(int k,double val) { if(k==end) { return val; } double val2; for(int i=node[k]; i!=-1; i=a[i].next) { double val1=a[i].val; int x=a[i].end; if(!(fabs(val1 - 0.0)<=eqs)&&level[x]==level[k]+1) { val2=dfs(x,min(val1,val)); if(!(fabs(val2- 0.0)<=eqs)) { node[k] = a[i].next; a[i].val -= val2; int j=a[i].pre; a[j].val += val2; return val2; } } } return 0; } double dinic() { double s = 0; while(bfs()) { for(int i=sta;i<=end;i++) { node[i] = pt[i]; } while(1) { double k = dfs(sta,inf); if(fabs(k - 0.0)<=eqs) { break; } s+=k; } } return s; }
相关文章推荐
- POJ 3308 Paratroopers 最小割、最大流
- poj_3308 Paratroopers(二分图最小点权覆盖集+dinic+化乘为加)
- POJ 3308 Paratroopers 最小点权覆盖 求最小割
- poj 3308 Paratroopers(二分图最小点权覆盖)
- 【POJ】【3308】Paratroopers
- POJ 3308 Paratroopers (对数转换+最小点权覆盖)
- poj 3308 Paratroopers 最小割 最小点权覆盖
- poj 3308 Paratroopers 最小割—最大流
- poj 3308 Paratroopers(网络流 最小割 dinic模板)
- poj 3308 Paratroopers
- POJ 3308 Paratroopers
- POJ 3308 Paratroopers (对数转换+最小点权覆盖)
- poj3308 Paratroopers --- 最小点权覆盖->最小割
- poj 3308 Paratroopers最小点权覆盖
- POJ 3308 Paratroopers(最小割EK(邻接表&矩阵))
- 【最小割】POJ-3308 Paratroopers
- POJ 3308 Paratroopers
- POJ 3308 Paratroopers (最小割)
- POJ 3308 Paratroopers (最小点权覆盖Dinic)
- POJ 3308 Paratroopers