poj 3041 Asteroids(二分图 *【矩阵实现】【最小点覆盖==最大匹配数】)
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 16379 | Accepted: 8930 |
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 <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <algorithm>
#define N 500+20
#define INF 0x3f3f3f3f using namespace std;
int n, m;
int map[N][N];
int link[N];
bool vis[N]; bool match( int u )
{
for(int i=1; i<=n; i++)
{
if(vis[i]==false && map[u][i]==1 )
{
vis[i]=true;
if(link[i]==-1 || match(link[i]) )
{
link[i]=u;
return true;
}
}
}
return false;
} int main()
{
int i, j, k;
int u, v;
scanf("%d %d", &n, &m);
memset(map, 0, sizeof(map)); for(i=0; i<m; i++ ){
scanf("%d %d", &u, &v);
map[u][v] = 1;
}
memset(link, -1, sizeof(link));
int ans=0; for(int i=1; i<=n; i++)
{
memset(vis, false, sizeof(vis));
if(match(i))
ans++; }
printf("%d\n", ans );
return 0;
}
poj 3041 Asteroids(二分图 *【矩阵实现】【最小点覆盖==最大匹配数】)的更多相关文章
- POJ 3041 Asteroids (二分图最小点覆盖)
题目链接:http://poj.org/problem?id=3041 在一个n*n的地图中,有m和障碍物,你每一次可以消除一行或者一列的障碍物,问你最少消除几次可以将障碍物全部清除. 用二分图将行( ...
- poj 3041 Asteroids (二分图的最大匹配 第一题)
题目:http://poj.org/problem?id=3041 题意:在某个n*n的空间内,分布有一些小行星,某人在里面打炮,放一枪后某一行或某一列的行星就都没了,让求最少的打炮数. 然后把每行x ...
- POJ 3041 Asteroids 二分图匹配
以行列为点建图,每个点(x,y) 对应一条边连接x,y.二分图的最小点覆盖=最大匹配 //#pragma comment(linker, "/STACK:1024000000,1024000 ...
- POJ 3041 Asteroids 二分图
原题连接:http://poj.org/problem?id=3041 Asteroids Time Limit: 1000MS Memory Limit: 65536K Total Submis ...
- poj - 3041 Asteroids (二分图最大匹配+匈牙利算法)
http://poj.org/problem?id=3041 在n*n的网格中有K颗小行星,小行星i的位置是(Ri,Ci),现在有一个强有力的武器能够用一发光速将一整行或一整列的小行星轰为灰烬,想要利 ...
- POJ 3041 Asteroids 二分图之最大匹配
题意:在一个网格中有若干个点,每一次可以清除一行或者一列,问最少几次可以将网格中的点全部清除. 思路:这个题是一个入门的最大匹配题(这个好像不是思路..).一般的方式就是将 行 看作集合A,列 看作集 ...
- 【网络流#6】POJ 3041 Asteroids 二分图最大匹配 - 《挑战程序设计竞赛》例题
学习网络流中ing...作为初学者练习是不可少的~~~构图方法因为书上很详细了,所以就简单说一说 把光束作为图的顶点,小行星当做连接顶点的边,建图,由于 最小顶点覆盖 等于 二分图最大匹配 ,因此求二 ...
- POJ 3041 Asteroids(二分图模板题)
Bessie wants to navigate her spaceship through a dangerous asteroid field in the shape of an N x N g ...
- POJ 3041 Asteroids / UESTC 253 Asteroids(二分图最大匹配,最小点匹配)
POJ 3041 Asteroids / UESTC 253 Asteroids(二分图最大匹配,最小点匹配) Description Bessie wants to navigate her spa ...
随机推荐
- springnodejs
作者 : solq 最新文档请看 http://www.springnodejs.com 本文不再更新 blog : http://www.cnblogs.com/solq/p/3574640.htm ...
- 收藏以下linux查看系统信息的命令
# uname -a # 查看内核/操作系统/CPU信息# head -n 1 /etc/issue # 查看操作系统版本# hostname ...
- Win7如何获得TrustedInstaller权限
将下面的信息保存为启用TakeOwnership.reg,双击注册即可 Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\*\sh ...
- swiper的理解
参考:Swiper中文网 Swiper使用方法: <!DOCTYPE html> <html> <head> <meta charset="UTF- ...
- (一)关于jQuery的网上资源
jQuery官网: http://jquery.com/ jQuery API: http://jquery.cuishifeng.cn/ w3school学习网站:http://www.w3scho ...
- void 0 或者 undefined
Problem 在检查一个值是否为undefined的时候.你们是假设去測试的? 要是之前的我会这样子測试 function isUndefined(obj){ return obj === unde ...
- List集合的遍历方法
估计你永远都不会忘记这三个方法了...... public static void main(String[] args) { //超级for循环遍历方法 List<String> lis ...
- Android 开源项目精选
0x00 leakcanary [内存泄漏检测] Leakcanary : A memory leak detection library for Android and Java. 良心企业Squ ...
- Hollis原创|不了解这12个语法糖,别说你会Java
GitHub 2.5k Star 的Java工程师成神之路 ,不来了解一下吗? GitHub 2.5k Star 的Java工程师成神之路 ,真的不来了解一下吗? GitHub 2.5k Star 的 ...
- 仿VS安装界面小球滑动效果
在Visual Studio 2010后续版本的安装界面中,可以发现一组小球在滑动表示安装程序正在进行: 于是尝试用CSS实现了一下. 首先需要建立用来表示小球的html结构: <div cla ...