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 10 00 5050 050 500 10001000 0
Sample Output
91.500000
Author: HE, Ningxu
Contest: ZOJ Monthly, January 2011
本題首先就是要仔細讀懂題目。
N個飛彈基地射擊M個目標,每個塔發射一個飛彈需要的時間為T1,然後T2時間之後才能發射另外一個飛彈。
此題用二分+二分匹配解決感覺太神奇了~~~~~
高效的二分,然後用二分匹配,多麼美妙啊。
要擴充為M*N個飛彈發射基地。二分時間限制,建圖,求最大匹配。
代碼:
/*大致題意:用n個飛彈發射塔攻擊m個目標。每個發射架在某個時刻只能為一顆飛彈服務,發射一顆飛彈需要準備t1的時間,一顆飛彈從發射到擊中目標的時間與目標到發射架的距離有關。每顆飛彈發射完成之後發射架需要t2的時間進入下個發射流程。現在問最少需要多少時間可以擊毀所有m個目標。大致思路:二分枚舉這個最大時間的最小值,每次按照這個枚舉的時間構出二分圖,求最大匹配來判定枚舉值是否符合要求。注意單位,T1要除於60轉化成分的*/#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;int linker[MAXN];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; if(linker[g[u][i]]==-1||dfs(linker[g[u][i]])) { linker[g[u][i]]=u; return true; } } } return false;}int hungary(){ int u; int res=0; memset(linker,-1,sizeof(linker)); 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;}