POJ_2536_Gopher II
题意:n只地鼠,m个地鼠洞,地鼠必须以v的速度在s秒内钻进洞且每个洞仅能容纳一只地鼠,问最少有几只地鼠会被老鹰吃掉。
分析:最大匹配问题,将s秒内地鼠能够跑到的洞与该地鼠连成一条边,在最后得到的图中使用匈牙利。
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
#define Del(x,y) memset(x,y,sizeof(x)) double xx[],yy[];
int n,m;
int map[][],vis[],link[]; bool dfs(int x)
{
for(int i=; i<=m; i++)
if(map[x][i]==&&vis[i]==)
{
vis[i]=;
if(link[i]==-||dfs(link[i]))
{
link[i]=x;
return true;
}
}
return false;
} void solve()
{
int ans=;
Del(link,-);
for(int i=; i<=n; i++)
{
Del(vis,);
if(dfs(i))
ans++;
}
printf("%d\n",n-ans);
} double dis(int i,double a,double b)
{
return sqrt((xx[i]-a)*(xx[i]-a)+(yy[i]-b)*(yy[i]-b));
} int main()
{
int s,v;
double p,q;
while(~scanf("%d%d%d%d",&n,&m,&s,&v))
{
for(int i=; i<=n; i++)
scanf("%lf%lf",&xx[i],&yy[i]);
Del(map,);
for(int i=; i<=m; i++)
{
scanf("%lf%lf",&p,&q);
for(int j=; j<=n; j++)
{
if(dis(j,p,q)<=(s*v))
map[j][i]=;
}
}
solve();
}
return ;
}
POJ_2536_Gopher II的更多相关文章
- Leetcode 笔记 113 - Path Sum II
题目链接:Path Sum II | LeetCode OJ Given a binary tree and a sum, find all root-to-leaf paths where each ...
- Leetcode 笔记 117 - Populating Next Right Pointers in Each Node II
题目链接:Populating Next Right Pointers in Each Node II | LeetCode OJ Follow up for problem "Popula ...
- 函数式Android编程(II):Kotlin语言的集合操作
原文标题:Functional Android (II): Collection operations in Kotlin 原文链接:http://antonioleiva.com/collectio ...
- 统计分析中Type I Error与Type II Error的区别
统计分析中Type I Error与Type II Error的区别 在统计分析中,经常提到Type I Error和Type II Error.他们的基本概念是什么?有什么区别? 下面的表格显示 b ...
- hdu1032 Train Problem II (卡特兰数)
题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能. (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...
- [LeetCode] Guess Number Higher or Lower II 猜数字大小之二
We are playing the Guess Game. The game is as follows: I pick a number from 1 to n. You have to gues ...
- [LeetCode] Number of Islands II 岛屿的数量之二
A 2d grid map of m rows and n columns is initially filled with water. We may perform an addLand oper ...
- [LeetCode] Palindrome Permutation II 回文全排列之二
Given a string s, return all the palindromic permutations (without duplicates) of it. Return an empt ...
- [LeetCode] Permutations II 全排列之二
Given a collection of numbers that might contain duplicates, return all possible unique permutations ...
随机推荐
- C++求解数组中出现超1/4的三个数字。
#include <iostream> using namespace std; //求x!中k因数的个数. int Grial(int x,int k) { int Ret = 0; w ...
- websphere修改jsp不生效的解决办法
最近在给客户部署系统后,进行UAT测试的时候,发现一些小问题(是一些jsp文件),改好后,就进行增量发布了,可是后来在页面刷新的时候,怎么都是显示不出来效果,后来就把服务websphere重启后,页面 ...
- iOS开发——高级篇——iOS 强制退出程序APP代码
1.先po代码 UIAlertView* alert = [[UIAlertView alloc] initWithTitle:self.exitapplication message:@" ...
- 【bzoj2748】[HAOI2012]音量调节
设F[i][j]表示在第i首歌曲结束后,音量能否刚好为j 转移:F[i][j]=F[i][j-C[i]] or F[i][j+C[i]] 初始化:F[0][beginlevel]=true 最后在所有 ...
- unigui组件中client javascript delphi组件之间的操作
UniLabel组件: function OnClick(sender, e){ MainForm.UniLabel1.setText('Click!');} function Onmousemove ...
- iOS开发-多台机器共用证书问题
今天又被证书的问题卡壳了: 在公司的电脑上申请的开发.发布证书,回家用自己的电脑从苹果开发者中心上将证书和配置文件都下载下来提示用不了,弄了很久才想起.p12文件,必须从申请证书的电脑上导出,导入到自 ...
- Killer Problem(暴力)
题意: 给定一个序列,每次询问l到r之间两个数差的绝对值的最小值. 分析: 开始以为是线段树离线处理,实际暴力就好! #include <map> #include <set> ...
- [Codeforces Education Round 6E] New Year Tree
[题目链接] https://codeforces.com/contest/620/problem/E [算法] 显然 , 一棵子树的DFS序必然为连续的一段 用线段树维护颜色数即可 [代码] #in ...
- securecrt中vim行号下划线问题及SecureCRT里root没有高亮的设置,修改linux终端命令行颜色
背景:在用raspberry用SecureCRT下的vim打开文件时出现用set nu时行有下划线,于是找了下解决办法,如下:vim行号下划线问题在vim中发现开启显示行号(set number) ...
- 2010–2011, NEERC, Northern Subregional C.Commuting Functions
C.Commuting Functions 由于要求答案字典序最小,我们肯定希望从g(1)开始对函数g进行赋值,于是又公式f(g(x))=g(f(x)) 设f(x)=i 我们推导出 由于f是双射,当i ...