POJ2536 二分圖最大匹配

初始化的時候double類型數轉化成int。。。。。wdnmd

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
const int maxn = 1e3+10;
using namespace std;
int tot,head[maxn],num;
struct Edge{
	int to,nxt;
}e[maxn*maxn];
int vis[maxn],link[maxn];

struct Node{
	double x,y;
	Node(double x,double y):x(x),y(y){}
}; 
vector<Node> gopher, pole;
void add(int from,int to)
{
	e[tot].nxt = head[from], e[tot].to = to;
	head[from] = tot++;
}
bool dfs(int fa)
{
	for(int i = head[fa]; ~i; i = e[i].nxt)
	{
		if(!vis[e[i].to])
		{
			vis[e[i].to] = 1; 
			if(!link[e[i].to] || dfs(link[e[i].to]))
			{
				link[e[i].to] = fa;
				return true;
			}
		} 
	}
	return false;
}
double dis(Node a,Node b)
{
	double dis = sqrt((b.y - a.y)*(b.y-a.y)+(b.x-a.x)*(b.x-a.x));
	return dis;
}
int main()
{
	int n,m,s,v;
	while(~scanf("%d%d%d%d",&n,&m,&s,&v))
	{
		memset(link,0,sizeof(link));
		memset(head,-1,sizeof(head)); tot = 0;
		gopher.clear(); pole.clear(); num = 0;
		double x,y;
		for(int i = 0; i < n; ++i) scanf("%lf%lf",&x,&y),gopher.push_back(Node(x,y));
		for(int i = 0; i < m; ++i) scanf("%lf%lf",&x,&y),pole.push_back(Node(x,y));
		for(int i = 0; i < gopher.size();++i)
		for(int j = 0; j < pole.size(); ++j)
		{
			if(dis(gopher[i],pole[j]) <= s*v) add(i+1,j+1+n);
		}
		for(int i = 1; i <= n; ++i)
		{
			memset(vis,0,sizeof(vis));
			if(dfs(i)) num++;
		}
		printf("%d\n",n-num);
	}
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章