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;
} 

最新文章

  1. 机器指令翻译成 JavaScript —— No.7 过渡语言
  2. Linux lsof命令 以及 恢复删除的文件
  3. 微信支付Native扫码支付模式二之CodeIgniter集成篇
  4. Mybatis 新增修改一条SQL
  5. Case1:WorkFlow不能运行的解决办法
  6. Android线程管理(二)&mdash;&mdash;ActivityThread
  7. Objective-C面向对象(三)
  8. Oracle 基础 游标
  9. [SAN4N学习笔记]使用SysTick精准延时
  10. call 方法在使用一个指定的this值和若干个指定的参数值的前提下调用某个函数或方法.
  11. [LeetCode 111] - 二叉树的最小深度 (Minimum Depth of Binary Tree)
  12. springMVC简单的安全防御配置
  13. javaSE(九)之泛型(Generics)
  14. Go 定时任务
  15. [Linux] 搭建rsync服务端
  16. per-CPU变量
  17. Datatables插件1.10.15版本服务器处理模式ajax获取分页数据实例解析
  18. postgresql命令
  19. android关闭日志
  20. python之pandas用法大全

热门文章

  1. 机器学习入门-随机森林预测温度-不同参数对结果的影响调参 1.RandomedSearchCV(随机参数组的选择) 2.GridSearchCV(网格参数搜索) 3.pprint(顺序打印) 4.rf.get_params(获得当前的输入参数)
  2. libcur+openssl的编译,使之支持SSL&lt;转&gt;
  3. 前端-CSS-9-文本和字体-背景颜色
  4. 【转】.net 实现 语音搜索(仅限WebKit内核浏览器)
  5. 状态图(Statechart Diagram)
  6. Why We Worry and What to Do About It
  7. linux添加root级别账户
  8. Retrofit2.0+RxJava2.0问题
  9. SpringCloud——Eureka服务注册和发现
  10. 第五章&#160;二叉树(e5)重构