【二分图】poj 2536 Gopher II

来源:互联网 发布:喜纳昌吉 知乎 编辑:程序博客网 时间:2024/05/22 12:44
Gopher II
Time Limit: 2000MS
Memory Limit: 65536KTotal Submissions: 9073
Accepted: 3772

Description

The 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.

Input

The 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.

Output

Output consists of a single line for each case, giving the number of vulnerable gophers.

Sample Input

2 2 5 101.0 1.02.0 2.0100.0 100.020.0 20.0

Sample Output

1

题目大意:

有n只地鼠的坐标,m个洞的坐标,地鼠的移动速度为v,在s秒以后会飞来一只老鹰要吃地鼠,问有多少个地鼠可能被吃。

解题思路:

二分图最大匹配,匹配多了一个条件判断距离而已。。。

注意最后输出的是未能逃跑的小鼠。。。WA了几发。。

///AC代码

#include <algorithm>#include <cmath>#include <cstdio>#include <cstring>#include <ctime>#include <iostream>#include <map>#include <queue>#include <set>#include <stack>#include <string>#include <vector>#define eps 1e-8#define INF 0x7fffffff#define maxn 100005#define PI acos(-1.0)using namespace std;typedef long long LL;const int N = 302;/*变种1:二分图的最小顶点覆盖:假如选了一个点就相当于覆盖了以它为端点的所有边,你需要选择最少的点来覆盖所有的边二分图的最小顶点覆盖数 = 二分图的最大匹配数变种2:DAG图(无回路有向图)的最小路径覆盖路径覆盖就是在图中找一些路经,使之覆盖了图中的所有顶点,且任何一个顶点有且只有一条路径与之关联,如果把这些路径中的每条路径从它的起始点走到它的终点,那么恰好可以经过图中的每个顶点一次且仅一次DAG图的最小路径覆盖数 = 节点数(n)- 最大匹配数(m)变种3: 二分图的最大独立集:在图中选取最多的点,使任意所选两点均不相连二分图的最大独立集数 = 节点数(n)- 最大匹配数(m)*//*=***************************************************二分图匹配(匈牙利算法的DFS实现)INIT:g[][]两边定点划分的情况CALL:res=hungary();输出最大匹配数优点:适于稠密图,DFS找增广路快,实现简洁易于理解时间复杂度:O(VE);***************************************************=*/const int MAXN = 1000;int uN, vN; //u,v数目int g[MAXN][MAXN];//编号是0~n-1的int linker[MAXN];bool used[MAXN];bool dfs(int u){    int v;    for (v = 1; v <= vN; v++)        if (g[u][v] && !used[v])        {            used[v] = true;            if (linker[v] == -1 || dfs(linker[v]))            {                linker[v] = u;                return true;            }        }    return false;}int hungary(){    int res = 0;    int u;    memset(linker, -1, sizeof(linker));    for (u = 1; u <= uN; u++)    {        memset(used, 0, sizeof(used));        if (dfs(u))        {            res++;        }    }    return res;}double far(double x1, double y1, double x2, double y2){    return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));}double a[110], b[110], pp[110], qq[110];int main(){    int n, m;    double s, v;    while (~scanf("%d%d%lf%lf", &n, &m, &s, &v))    {        memset(g, 0, sizeof(g));        memset(a, 0, sizeof(a));        memset(b, 0, sizeof(b));        memset(qq, 0, sizeof(qq));        memset(pp, 0, sizeof(pp));        uN = n;        vN = m;        double stder = s * v * 1.0;        for (int i = 1; i <= n; i++)        {            scanf("%lf%lf", &a[i], &b[i]);        }        for (int i = 1; i <= m; i++)        {            scanf("%lf%lf", &pp[i], &qq[i]);        }        for (int i = 1; i <= n; i++)        {            for (int j = 1; j <= m; j++)            {                if (far(a[i], b[i], pp[j], qq[j]) <= stder)                {                    g[i][j] = 1;                }            }        }        int ans = hungary();        cout << n - ans << endl;    }    return 0;}


 
原创粉丝点击