POJ2536(二分图最大匹配)
2016-09-04 09:25
120 查看
Gopher II
DescriptionThe gopher family, having averted the canine threat, must face a new predator.The are n gophers and m gopher holes, each at distinct (x, y) coordinates. A hawk arrives and if a gopher does not reach a hole in s seconds it is vulnerable to being eaten. A hole can save at most one gopher. All the gophers run at the same velocity v. The gopher family needs an escape strategy that minimizes the number of vulnerable gophers.
InputThe input contains several cases. The first line of each case contains four positive integers less than 100: n, m, s, and v. The next n lines give the coordinates of the gophers; the following m lines give the coordinates of the gopher holes. All distances are in metres; all times are in seconds; all velocities are in metres per second.
OutputOutput consists of a single line for each case, giving the number of vulnerable gophers.
Sample Input
Sample Output
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 8504 | Accepted: 3515 |
InputThe input contains several cases. The first line of each case contains four positive integers less than 100: n, m, s, and v. The next n lines give the coordinates of the gophers; the following m lines give the coordinates of the gopher holes. All distances are in metres; all times are in seconds; all velocities are in metres per second.
OutputOutput consists of a single line for each case, giving the number of vulnerable gophers.
Sample Input
2 2 5 10 1.0 1.0 2.0 2.0 100.0 100.0 20.0 20.0
Sample Output
1 思路:若gopher能到达hole,则在两者之间建一条边。答案为 n-二分图最大匹配。
#include <cstdio> #include <cmath> #include <vector> #include <cstring> using namespace std; const int MAXN=205; struct Node{ double x,y; }gopher[MAXN],hole[MAXN]; int n,m,s,v; double dist(double x1,double y1,double x2,double y2) { return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); } vector<int> arc[MAXN]; int match[MAXN],vis[MAXN]; bool dfs(int u) { for(int i=0;i<arc[u].size();i++) { int to=arc[u][i]; if(!vis[to]) { vis[to]=1; int w=match[to]; if(w==-1||dfs(w)) { match[u]=to; match[to]=u; return true; } } } return false; } int max_flow() { int ans=0; memset(match,-1,sizeof(match)); for(int i=1;i<=n;i++) { if(match[i]==-1) { memset(vis,0,sizeof(vis)); if(dfs(i)) ans++; } } return ans; } int main() { while(scanf("%d%d%d%d",&n,&m,&s,&v)!=EOF) { for(int i=1;i<MAXN;i++) arc[i].clear(); for(int i=1;i<=n;i++) { scanf("%lf%lf",&gopher[i].x,&gopher[i].y); } for(int i=1;i<=m;i++) { scanf("%lf%lf",&hole[i].x,&hole[i].y); } for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { double d=dist(gopher[i].x,gopher[i].y,hole[j].x,hole[j].y); if(v*s>=d) { int u=i,v=j+n; arc[u].push_back(v); arc[v].push_back(u); } } } int res=max_flow(); printf("%d\n",n-res); } return 0; }
相关文章推荐
- POJ2536 Gopher II(二分图最大匹配)
- POJ2536_Gopher II(二分图最大匹配)
- POJ2536 Gopher II【二分图最大匹配】
- 二分图最大匹配--poj2536
- 网络最大流、二分图最大匹配、POJ2536
- POJ2536 Gopher II【二分图最大匹配】
- hdu 二分图最大匹配问题 (hdu 1083)
- hdu 2444 二分图判定+最大匹配
- 二分图最大匹配--匈牙利算法
- 二分图最大匹配 匈牙利算法 (自己写的模板)
- hdu 3395(费用流,二分图的最大权匹配)
- HDU 2063 二分图最大匹配 解题报告
- 【二分图最大权匹配---KM算法】
- 杭电 hdu 1528 Card Game Cheater (二分图,最大匹配)
- hdu 1150 二分图 最小点覆盖=最大匹配
- HDU 2444 The Accomodation of Students (二分图存在的判定以及最大匹配数)
- 关于二分图的最大权匹配
- Kuhn-Munkres算法(二分图最大权匹配)
- hdu 3729 I'm Telling the Truth(二分图最大匹配)
- poj 3041 Asteroids 二分图最小点覆盖=最大匹配