zoukankan      html  css  js  c++  java
  • poj 2536 GopherII(二分图匹配)

    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个只能装的下一只老鼠的老鼠洞,老鼠和老鼠洞的坐标已给出,老鹰在S秒后来到,老鼠的速度全部为V,问最少有多少老鼠来不及进洞
    简单的二分图匹配算法,直接贴出代码:
    #include<iostream>
    #include<string.h>
    #include<cmath>
    using namespace std;
    int map[200][200],v[200];
    double x[200],y[200],xx,yy;
    int match[200];
    int N,M,S,V;
    double disIsOK(double x1,double y1,double x2,double y2){
        return S*V>=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
    }
    int dfs(int ii){
        for(int i=1;i<=N;i++){
            if(map[i][ii]&&!v[i]){
                v[i]=1;
                if(match[i]==0||dfs(match[i])){
                    match[i]=ii;return 1;
                }
            }
        }
        return 0;
    }
    int main(){
        while(cin>>N>>M>>S>>V){
            memset(map,0,sizeof(map));
            memset(match,0,sizeof(match));
            for(int i=1;i<=N;i++){
                cin>>x[i]>>y[i];
            }
            for(int i=1;i<=M;i++){
                cin>>xx>>yy;
                for(int j=1;j<=N;j++){
                    if(disIsOK(x[j],y[j],xx,yy)){
                        map[j][i]=1;
                    }
                }
            }
            int res=0;
            for(int i=1;i<=M;i++){
                memset(v,0,sizeof(v));
                if(dfs(i))res++;
            }
            cout<<N-res<<endl;
        }
        return 0;
    }

    结果截图:


  • 相关阅读:
    SpringBoot集成Mybatis
    springboot通过slf4j配置日志
    SpringBoot导入jsp依赖始终报错
    shiro小记
    阿里开发手册华山版——(编程规约篇)记录目前自己不合理的地方
    [网络流24题] 2. 太空飞行计划问题 解题报告
    LOJ 6089 小 Y 的背包计数问题 解题报告 (动态规划)
    UVA 10599 Blocks 解题报告 (动态规划)
    Comet OJ#12E Ternary String Counting 解题报告
    [WC2016]挑战NPC 解题报告
  • 原文地址:https://www.cnblogs.com/yifan2016/p/5255632.html
Copyright © 2011-2022 走看看