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 ...
随机推荐
- Android入门级编译错误汇总
1 描写叙述: 项目常常须要引用别人的libraryproject,在选项中add进来后,点击应用或者确定.关闭页面. 回到代码中却发现无法链接,又一次打开properties查看,发现导入的pr ...
- Redis源代码分析(六)--- ziplist压缩列表
ziplist和之前我解析过的adlist列表名字看上去的非常像.可是作用却全然不同.之前的adlist主要针对的是普通的数据链表操作. 而今天的ziplist指的是压缩链表.为什么叫压缩链表呢.由于 ...
- 自己定义ViewGroup控件(一)----->流式布局进阶(一)
main.xml <? xml version="1.0" encoding="utf-8"?> <com.example.SimpleLay ...
- 在不同的系统中的virtualbox中安装Ubuntu SDK
对非常多的开发人员来说.你们可能使用的不是Ubuntu操作系统.在这样的情况下,开发人员须要在自己的操作系统中(OS X及Windows)安装virtualbox,并在VirtualBox中安装Ubu ...
- 如何遍历newtonsoft.json的JObject里的JSON数据
这种问题,在网上搜,居然没有答案,又是一堆垃圾,连谷歌上都搜不到.老实说,我喜欢这边的工作环境,可以上谷歌,毕竟是大公司,有自己的VPN .某组织整天禁这个禁那个,去年居然连谷歌都禁了,丧心病狂至此, ...
- yispider 开源小说採集器 (来源http://git.oschina.net/yispider/yispider 我的改动版由于他的我无法跑)
我的git地址 http://git.oschina.net/yangdc/yispider 小说採集器 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/ ...
- uclibc,eglibc,glibc之间的区别和联系【转】
本文转载自:https://www.crifan.com/relation_between_uclibc_glibc_eglibc/ [glibc,uclibc,eglibc的简介] 1.Glibc ...
- YTU 2632: B2 友元光顾
2632: B2 友元光顾 时间限制: 1 Sec 内存限制: 128 MB 提交: 378 解决: 241 题目描述 定义一个平面上的点类Point,其中设置成员函数distance1求当前对象 ...
- CollapsingToolbarLayout Toolbar的title覆盖问题
CollapsingToolbarLayout 里: 1 2 app:titleEnabled="true" app:title="Hello" Toolbar ...
- android删除短信
代码如下: //删除短信 getContentResolver().delete(Uri.parse("content://sms/#"),"address=?" ...