Asteroids - poj 3041(二分图最大匹配问题)
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 17258 | Accepted: 9386 |
Description
Fortunately, Bessie has a powerful weapon that can vaporize all the asteroids in any given row or column of the grid with a single shot.This weapon is quite expensive, so she wishes to use it sparingly.Given the location of all the asteroids in the field, find the minimum number of shots Bessie needs to fire to eliminate all of the asteroids.
Input
* Lines 2..K+1: Each line contains two space-separated integers R and C (1 <= R, C <= N) denoting the row and column coordinates of an asteroid, respectively.
Output
Sample Input
3 4
1 1
1 3
2 2
3 2
Sample Output
2
Hint
The following diagram represents the data, where "X" is an asteroid and "." is empty space:
X.X
.X.
.X.
OUTPUT DETAILS:
Bessie may fire across row 1 to destroy the asteroids at (1,1) and (1,3), and then she may fire down column 2 to destroy the asteroids at (2,2) and (3,2).
#include <iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
int map[][];
int vis[],match[];
int m,n;
int DFS(int p){
int v;
for(int i=;i<=m;i++){
if(map[p][i]&&!vis[i]){
vis[i]=;
v=match[i];
if( v==- || DFS(v)){
match[i]=p;
return ;
} }
}
return ;
}
int main() {
while(~scanf("%d %d",&m,&n)){
memset(map,,**sizeof(int));
for(int i=;i<n;i++){
int a,b;
scanf("%d %d",&a,&b);
map[a][b]=;
}
int result=;
memset(match,-,*sizeof(int));
for(int i=;i<=m;i++){
memset(vis,,*sizeof(int));
result+=DFS(i);
}
printf("%d\n",result);
}
return ;
}
Asteroids - poj 3041(二分图最大匹配问题)的更多相关文章
- Asteroids POJ - 3041 二分图最小点覆盖
Asteroids POJ - 3041 Bessie wants to navigate her spaceship through a dangerous asteroid field in ...
- Asteroids POJ - 3041
Asteroids POJ - 3041 题目大意:N*N的地图里,存在一些小行星,Bessie有个很牛x但又很耗蓝的武器,一次可以消灭一行或者一列的所有小行星,问最少使用多少次这个武器可以消灭所有的 ...
- poj 2239 二分图最大匹配,基础题
1.poj 2239 Selecting Courses 二分图最大匹配问题 2.总结:看到一个题解,直接用三维数组做的,很巧妙,很暴力.. 题意:N种课,给出时间,每种课在星期几的第几节课上 ...
- POJ 2226二分图最大匹配
匈牙利算法是由匈牙利数学家Edmonds于1965年提出,因而得名.匈牙利算法是基于Hall定理中充分性证明的思想,它是二部图匹配最常见的算法,该算法的核心就是寻找增广路径,它是一种用增广路径求二分图 ...
- POJ Evacuation /// 二分图最大匹配
题目大意: 在一个n*m的房间中 ‘X’为墙 ‘D’为门 ‘.’为人 门只存在与外围 人每秒钟只能向四连通区域走一步 门比较狭窄 每秒钟只能通过一个人 求所有人逃脱的最短时间 如果不可能则输出impo ...
- Asteroids POJ - 3041 【最小点覆盖集】
Bessie wants to navigate her spaceship through a dangerous asteroid field in the shape of an N x N g ...
- POJ 3041 -- 二分图匹配
题意:有个N*N的网格,有一部分格子里有陨石,小明有很牛逼的武器,打一枪后一行或一列的陨石就没了,给出陨石分布,求最小打炮数. 分析:其实就是Konig定理.记最小打炮数为m,在网格里你最多可以找出M ...
- poj 2724 二分图最大匹配
题意: 会给出M个串,我们要做的就是将这M个串给清除了.对于任意两个串,若二进制形式只有一位不一样,那么这两个串可以在一次操作消除,否则每个操作只能消除一个串. 3 3 *01 100 011 可以代 ...
- poj 2446 二分图最大匹配
思路:由(i+j)为偶数的点向(i+j)为奇数的点建边.求一次最大匹配,若正好为空格数(不包含洞)的一半,即输出YES. #include<iostream> #include<cs ...
随机推荐
- 乐观锁-version的使用
出处:http://chenzhou123520.iteye.com/blog/1863407 乐观锁介绍: 乐观锁( Optimistic Locking ) 相对悲观锁而言,乐观锁假设认为数据一般 ...
- 浅谈Uber与滴滴快的提供差异化服务带来的商业模式思考
一.引言 滴滴和快的烧钱的时代已经过去,在那个时代我们消费者着实得到了不少实惠.自从他们温柔的在一起之后,这种实惠就木有了.让我不禁感叹坐车的几率有降低了50%.前段时间,Uber悄无声息的进入我的视 ...
- 使用.Net中的WeakDictionary — ConditionalWeakTable
有的时候,我们需要给某些数据添加一些附加信息,一种常用的做法是使用一个Dictionary在填充这些附加信息如: var data = new Data(); var tag = new Tag ...
- 利用Impromptu实现duck typing的封装
Impromptu是一个动态生成代码实现接口的库,可以非常方便我们实现DuckType编程: public interface IUser { string Name { get; ...
- 解决Ubuntu 14下,PhpStorm 9.x 编辑器界面中文乱码的问题
在Ubuntu 14中,安装了 PhpStorm 9.02,发现 软件界面中文乱码,但是源码编辑处却显示正常,如下图所示: 很奇怪,猜想,应该是软件界面字体有问题,选了一个没有包含中文字体的字体.先前 ...
- 更合理的 setState()
原文发表在我的博客:http://www.erichain.me/2017/04/17/2017-04-17-more-reasonable-setstate/ React 是我做前端以来接触到的第三 ...
- 简单抓取安居客房产数据,并保存到Oracle数据库
思路和上一篇差不多,先获取网站html文件,使用BeautifulSoup进行解析,将对应属性取出,逐一处理,最后把整理出的记录保存到oracle中,持久化储存. '''Created on 2017 ...
- NET PROVIDER 连接 Oracle数据库
NET 数据库连接 ORacle http://www.devart.com/ DataDirect http://www.datadirect.com/ Oracle免客户端For . ...
- android 电话薄先10位匹配,若是无法匹配,则换成7位匹配
案例 1: 假设您保存的有:A:04165191666. B:5191666. 来电号码是:04165191666 由于是7位匹配,所以A和B都能够匹配到.可是最佳匹配还是A,最后显示A: 来电 ...
- ylbtech-LanguageSamples-Attibutes(特性)
ylbtech-Microsoft-CSharpSamples:ylbtech-LanguageSamples-Attibutes(特性) 1.A,示例(Sample) 返回顶部 “特性”示例 本示例 ...