POJ 3041 Asteroids 最小点覆盖 == 二分图的最大匹配
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
#include <stdio.h>
#include <string.h> int n, k, link[];
bool map[][], vis[]; bool dfs(int u)
{
for(int v = ; v <= n; v++)
{
if(map[u][v] && !vis[v])
{
vis[v] = ;
if(link[v] == - || dfs(link[v]))
{
link[v] = u;
return ;
}
}
}
return ;
} int main()
{
int x, y;
while(scanf("%d %d", &n, &k) != EOF)
{
memset(map, , sizeof(map));
memset(link, -, (n+)*sizeof(int));
while(k--)
{
scanf("%d %d", &x, &y);
map[x][y] = ;
}
int ans = ;
for(int i = ; i <= n; i++)
{
memset(vis, , (n+)*sizeof(bool));
if(dfs(i))
ans++;
}
printf("%d\n", ans);
}
return ;
}
POJ 3041 Asteroids 最小点覆盖 == 二分图的最大匹配的更多相关文章
- poj 3041 Asteroids 最小点覆盖/最大匹配
Asteroids Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16242 Accepted: 8833 Descriptio ...
- [poj] 3041 Asteroids || 最小点覆盖=最大二分图匹配
原题 本题为最小点覆盖,而最小点覆盖=最大二分图匹配 //最小点覆盖:用最少的点(左右两边集合的点)让每条边都至少和其中一个点关联. #include<cstdio> #include&l ...
- poj 3041 Asteroids(最小点覆盖)
http://poj.org/problem?id=3041 Asteroids Time Limit: 1000MS Memory Limit: 65536K Total Submissions ...
- POJ 3041 Asteroids (最小点覆盖集)
题意 给出一个N*N的矩阵,有些格子上有障碍,要求每次消除一行或者一列的障碍,最少消除多少次可以全部清除障碍. 思路 把关键点取出来:一个障碍至少需要被它的行或者列中的一个消除. 也许是最近在做二分图 ...
- 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.Asteroids 最小顶点覆盖
Asteroids Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22905 Accepted: 12421 Descr ...
- POJ 3041(最小点覆盖)
题意: 假如你如今正处在一个N*N的矩阵中,这个矩阵里面有K个障碍物,你拥有一把武器,一发弹药一次能消灭一行或一列的障碍物,求最小的弹药消灭所有障碍物 输入为: N K 接下来有K行,每行包括 ...
- PKU 3041 Asteroids 最小点覆盖(最大匹配模板题)
题目大意:给你一个N*N的矩阵, 里面有K个星球, 我们可以让武器攻击矩阵的一行或者一列来使得这个星球被击碎, 现在问你最少需要几个这种武器才能把所有的星球击碎? 解题思路:关键是建模构图 把每一行当 ...
- POJ 3041 Asteroids 最小覆盖数
http://poj.org/problem?id=3041 题目大意: 一辆宇宙飞船在一个小行星带中,你知道,这很危险.他有一种武器,可以清除掉一行或一列的小行星.问把小行星全部清除最少的武器使用次 ...
随机推荐
- JavaScript- 省市联动代码
以下是JS省市联动菜单代码: 代码一: <html> <head> <title></title> <script language=" ...
- 【转载】ABAP-如何读取内表的字段名称
原文地址:ABAP-如何读取内表的字段名称 *&---------------------------------------------------------------------* ...
- 【转】Android Camera(五)使用Camera功能 AREA的理解
http://blog.csdn.net/think_soft/article/details/7998478 使用Camera功能 大多数的Camera功能都是使用Camera.Parameters ...
- 在String中添加移动构造函数和移动赋值运算符
13.50 没有定义析构函数 #include<iostream> #include<string> #include<memory> #include<ut ...
- VC printf输出彩色字体
在VC下使用SetConsoleTextAttribute()函数可以改变当前控制台的前景色和背景色,从而达到输出彩色字体的效果. 使用的方法也很简单,具体代码如下: #include <win ...
- windows 下rabbitmq 安装---转载
原文地址:http://blog.sina.com.cn/s/blog_7cc0c8cc0101mb4a.html 1.下载并安装erlang,http://www.erlang.org/downlo ...
- Android开发之ViewPager实现轮播图(轮播广告)效果的自定义View
最近开发中需要做一个类似京东首页那样的广告轮播效果,于是采用ViewPager自己自定义了一个轮播图效果的View. 主要原理就是利用定时任务器定时切换ViewPager的页面. 效果图如下: 主页面 ...
- Windows系统下搭建Jenkins环境
1. 安装JDK JDK下载地址: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.ht ...
- ThinkPHP的数据库访问的简单操作
传统的sql与ThinkPHP中的sql相比较 以user表为例 $user=M('user'); 1: SELECT * FROM user----------$user->select( ...
- XML--小结①