标签:
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 8504 | Accepted: 3515 |
Description
Input
Output
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; }
标签:
原文地址:http://www.cnblogs.com/program-ccc/p/5838638.html