Gopher II

Time Limit: 2000MS Memory Limit: 65536K

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

Source

Waterloo local 2001.01.27

一道二分图匹配的板子题,感觉dinic" role="presentation" style="position: relative;">dinicdinic算法快的飞起,于是我写了个dinic" role="presentation" style="position: relative;">dinicdinic求二分图最大匹配,其他没什么,就是建图的时候要记住判定地鼠到洞的距离是否合法就行了,还有就是多组数据记得要重置数组和cnt" role="presentation" style="position: relative;">cntcnt

代码如下:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<cmath>
#define N 300
#define M 100000
using namespace std;
struct pot{double x,y;}p[N];
int n,m,T,V,s,t,cnt,first[N],d[N];
struct edge{int v,next,c;}e[M];
inline void add(int u,int v,int c){
    e[++cnt].v=v;
    e[cnt].c=c;
    e[cnt].next=first[u];
    first[u]=cnt;
}
inline bool bfs(){
    queue<int>q;
    memset(d,-1,sizeof(d));
    d[s]=0;
    q.push(s);
    while(!q.empty()){
        int x=q.front();
        q.pop();
        for(int i=first[x];i!=-1;i=e[i].next){
            int v=e[i].v;
            if(d[v]!=-1||e[i].c<=0)continue;
            d[v]=d[x]+1;
            if(v==t)return true;
            q.push(v);
        }
    }
    return false;
}
inline int dfs(int p,int f){
    if(p==t||!f)return f;
    int flow=f;
    for(int i=first[p];i!=-1;i=e[i].next){
        int v=e[i].v;
        if(d[v]==d[p]+1&&e[i].c>0&&flow){
            int tmp=dfs(v,min(flow,e[i].c));
            if(!tmp)d[v]=-1;
            e[i].c-=tmp;
            e[i^1].c+=tmp;
            flow-=tmp;
        }
    }
    return f-flow;
}
inline double dis(pot a,pot b){return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}
int main(){
    while(~scanf("%d%d%d%d",&n,&m,&T,&V)){
        s=0,t=n+m+1;
        int len=T*V;
        cnt=-1;
        memset(first,-1,sizeof(first));
        for(int i=1;i<=n+m;++i)scanf("%lf%lf",&p[i].x,&p[i].y);
        for(int i=1;i<=n;++i)add(s,i,1),add(i,s,0);
        for(int i=n+1;i<=n+m;++i)add(i,t,1),add(t,i,0);
        for(int i=1;i<=n;++i)
            for(int j=n+1;j<=n+m;++j)
                if(dis(p[i],p[j])<=len*1.0)add(i,j,1),add(j,i,0);
        int ans=0;
        while(bfs())ans+=dfs(s,0x3f3f3f3f);
        printf("%d\n",n-ans);
    }
    return 0;
} 

2018.07.06 POJ2536 Gopher II(二分图匹配)的更多相关文章

  1. POJ2536 Gopher II(二分图最大匹配)

    Gopher II Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9005   Accepted: 3724 Descrip ...

  2. poj 2536 Gopher II (二分匹配)

    Gopher II Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6345   Accepted: 2599 Descrip ...

  3. HDU-3081-Marriage Match II 二分图匹配+并查集 OR 二分+最大流

    二分+最大流: 1 //题目大意:有编号为1~n的女生和1~n的男生配对 2 // 3 //首先输入m组,a,b表示编号为a的女生没有和编号为b的男生吵过架 4 // 5 //然后输入f组,c,d表示 ...

  4. 2018.06.27Going Home(二分图匹配)

    Going Home Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 24716 Accepted: 12383 Descript ...

  5. POJ2536 Gopher II【二分图最大匹配】

    题目链接: http://poj.org/problem? id=2536 题目大意: 有N仅仅鼹鼠和M个洞穴,假设鼹鼠在S秒内不可以跑到洞穴,就会被老鹰捉住吃掉. 鼹鼠跑的速度为V米/秒. 已知一个 ...

  6. 2018.07.06 POJ1698 Alice's Chance(最大流)

    Alice's Chance Time Limit: 1000MS Memory Limit: 10000K Description Alice, a charming girl, have been ...

  7. 2018.07.06 POJ1556 The Doors(最短路)

    The Doors Time Limit: 1000MS Memory Limit: 10000K Description You are to find the length of the shor ...

  8. EZ 2018 07 06 NOIP模拟赛

    又是慈溪那边给的题目,这次终于没有像上次那样尴尬了, T1拿到了较高的暴力分,T2没写炸,然后T3写了一个优雅的暴力就203pts,Rank3了. 听说其它学校的分数普遍100+,那我们学校还不是强到 ...

  9. 2018.07.06 BZOJ 1588: HNOI2002营业额统计(非旋treap)

    1588: [HNOI2002]营业额统计 Time Limit: 5 Sec Memory Limit: 162 MB Description 营业额统计 Tiger最近被公司升任为营业部经理,他上 ...

随机推荐

  1. springMVC获取用户的数据

    打算记录网站的访问信息,没有眉目,下记下参考. SpringMVC-获得用户请求数据

  2. SQL 2012 分页取数据

    ,), data int ) select * from t1 row rows only create clustered index t1c on t1(id) declare @i int ) ...

  3. DOS系统变量

    %ALLUSERSPROFILE% : 列出所有用户Profile文件位置.%APPDATA% : 列出应用程序数据的默认存放位置.%CD% : 列出当前目录.%CLIENTNAME% : 列出联接到 ...

  4. WDA-FPM-1-Roadmap(GAF)

    转载:https://www.cnblogs.com/sapSB/p/10077564.html 首先要有个简单的认识: 1.FPM支持的几种UI配置界面接口: Object Instance Flo ...

  5. vue深入了解组件——插槽

    一.插槽内容 Vue实现了一套内容分发的API,这套API基于当前的Web Components规范草案,将 <slot>  元素作为承载分发的内容的出口. 它允许你像这样合成组件: &l ...

  6. 迷你MVVM框架 avalonjs 学习教程20、路由系统

    SPA的成功离开不这三个东西,分层架构,路由系统,储存系统.分层架构是我们组织复杂代码的关键,这里特指MVVM的avalon:路由系统是将多个页面压缩在一个页面的关键:储存系统特指本地储存,是安全保存 ...

  7. mysql 建库建表建用户

    1.创建数据库 create database school; 2.使用数据库 Use school; 3.创建用户 create user jame@localhost identified by ...

  8. JSP技术复习

    JSP是一种运行在服务器端的脚本语言,是用来开发动态网页的技术,它是Java Web程序的开发重要技术 JSP页面主要由HTML和JSP代码构成,JSP代码是通过"<%"和& ...

  9. Java对称与非对称加密解密,AES与RSA

    加密技术可以分为对称与非对称两种. 对称加密,解密,即加密与解密用的是同一把秘钥,常用的对称加密技术有DES,AES等 而非对称技术,加密与解密用的是不同的秘钥,常用的非对称加密技术有RSA等 为什么 ...

  10. angularjs动态添加节点时,绑定到$scope中

    <html> <head> <meta charset="utf-8"/> <script src="https://cdn.b ...