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 ...
随机推荐
- python uzip
import zipfile import osdef un_zip(file_name): """unzip zip file""" zi ...
- [DLX反复覆盖] poj 1084 Square Destroyer
题意: n*n的矩形阵(n<=5),由2*n*(n+1)根火柴构成,那么当中会有非常多诸如边长为1,为2...为n的正方形,如今能够拿走一些火柴,那么就会有一些正方形被破坏掉. 求在已经拿走一些 ...
- NDK开发,没有你想象的那么难
NDK:Native Development Kit原生开发工具 NDK能干什么:NDK使得在android中,java能够调用C函数库. 为什么要用NDK:我们都知道.java是半解释型语言,非常e ...
- PNG vs. GIF vs. JPEG vs. SVG - When best to use?
image - PNG vs. GIF vs. JPEG vs. SVG - When best to use? - Stack Overflow https://stackoverflow.com/ ...
- Use of implicitly declared global variable
https://stackoverflow.com/questions/7604419/resharper-javascript-use-of-implicitly-declared-global-v ...
- 【Dairy】2016.10.24 - made 嘲讽垃圾
//这个还找不到我的博客,但在看到原文 //这个还找不到我的博客,但在看到原文 //这个还找不到我的博客,但在看到原文 //这个还在我前面,访问多 一波嘲讽,woc 今天百度一下文章,发现有一篇和我一 ...
- [翻译]NUnit---String && Collection && File && Directory Assert (七)
StringAssert (NUnit 2.2.3) StringAssert类提供一系列检查字符串的方法. CollectionAssert (NUnit 2.4 / 2.5) Collection ...
- android 制作9.png图片
什么叫.9.PNG呢,这是安卓开发里面的一种特殊的图片 这种格式的图片在android 环境下具有自适应调节大小的能力. (1)允许开发人员定义可扩展区域,当需要延伸图片以填充比图片本身更大区 ...
- bzoj 1497(最大权闭合子图)
1497: [NOI2006]最大获利 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 6410 Solved: 3099[Submit][Status] ...
- BZOJ_1493_[NOI2007]项链工厂_Splay
BZOJ_1493_[NOI2007]项链工厂_Splay Description T公司是一家专门生产彩色珠子项链的公司,其生产的项链设计新颖.款式多样.价格适中,广受青年人的喜爱. 最近T公司打算 ...