【二分图】poj 2536 Gopher II

Gopher II
Time Limit: 2000MS
Memory Limit: 65536K
Total 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 10
1.0 1.0
2.0 2.0
100.0 100.0
20.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;
}


 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值