## ZOJ 3460 Missile（二分+二分匹配）

Missile

Time Limit: 2 Seconds      Memory Limit: 65536 KB

You control N missile launching towers. Every tower has enough missiles, but for each tower only one missile can be launch at the same time. Before the launching, every missile need T1 seconds to leave the tower. Assume that all the missiles have the same speed V, and it would fly along the shortest path to the target. You can just consider the horizontal distance and ignore the height. You can consider the time equal to distance / V (minutes). The missile can immediately destroy the target when it reached. Besides, for the same tower, after launching a missile, it need T2 minutes to prepare for the next one.

Now, give you the coordinate position of N missile launching towers and M targets, T1, T2 and V, you should find the minimum minutes to destroy all the targets.

#### Input

The input will consist of about 10 cases. The first line of each case contains five positive integer numbers N, M, T1, T2 and V, decribed as above. The next M lines contains two integer numbers indicating the coordinate of M targets. The continueing N lines contains two integer numbers indicating the coordinate of N towers.
To all the cases, 1 ≤ N ≤ 50, 1 ≤ M ≤ 50
The absolute value of all the coordinates will not exceed 10000, T1, T2, V will not exceed 2000.

#### Output

For each case, the output is only one line containing only one real number with six digits precision (after a decimal point) indicating the minimum minutes to destroy all the targets.

#### Sample Input

3 3 30 20 1
0 0
0 50
50 0
50 50
0 1000
1000 0


#### Sample Output

91.500000


Author: HE, Ningxu
Contest: ZOJ Monthly, January 2011

N个导弹基地射击M个目标，每个塔发射一个导弹需要的时间为T1，然后T2时间之后才能发射另外一个导弹。

/*

*/

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
using namespace std;
const double eps=1e-8;
const int MAXN=2550;
bool used[MAXN];
vector<int>g[60];
int uN;
bool dfs(int u)
{
for(int i=0;i<g[u].size();i++)
{
if(!used[g[u][i]])
{
used[g[u][i]]=true;
{
return true;
}
}
}
return false;
}
int hungary()
{
int u;
int res=0;
for(u=0;u<uN;u++)
{
memset(used,false,sizeof(used));
if(dfs(u))res++;
}
return res;
}

int N,M;
double  T1,T2,V;
struct Node
{
int x,y;
};
Node node1[60],node2[60];
double d[60][60];
double tt[MAXN][60];

double dis(Node a,Node b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}

void init()
{
for(int i=0;i<N;i++)
for(int j=0;j<M;j++)
d[i][j]=dis(node1[i],node2[j]);
for(int k=0;k<M;k++)
for(int i=0;i<N;i++)
for(int j=0;j<M;j++)
{
tt[i*M+k][j]=k*T2+(k+1)*T1+d[i][j]/V;
}
uN=M;
}

double solve()
{
double l=0;
double r=200000000000.0;
double mid;
while(r-l>=eps)
{
mid=(l+r)/2;
for(int i=0;i<M;i++)g[i].clear();
for(int i=0;i<M*N;i++)
for(int j=0;j<M;j++)
{
if(tt[i][j]<=mid)g[j].push_back(i);
}
if(hungary()==M)
{
r=mid;
}
else l=mid;
}
printf("%.6lf\n",r);
}
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
while(scanf("%d%d%lf%lf%lf",&N,&M,&T1,&T2,&V)!=EOF)
{
T1/=60;//这个注意，没有除一直得不到答案，纠结
for(int i=0;i<M;i++)scanf("%d%d",&node2[i].x,&node2[i].y);
for(int i=0;i<N;i++)scanf("%d%d",&node1[i].x,&node1[i].y);
init();
solve();
}
return 0;
}

posted on 2012-10-05 00:00  kuangbin  阅读(444)  评论(0编辑  收藏

JAVASCRIPT: