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 题目大意: 一辆宇宙飞船在一个小行星带中,你知道,这很危险.他有一种武器,可以清除掉一行或一列的小行星.问把小行星全部清除最少的武器使用次 ...
随机推荐
- iOS socket原理及连接过程详解
连接过程图解(度娘的拿过来用)
- java数据库连接池dbcp的使用
近年来,随着Internet/Intranet建网技术的飞速发展和在世界范围内的迅速普及,计算机 应用程序已从传统的桌面应用转到Web应用.基于B/S(Browser/Server)架构的3层开发模式 ...
- NuGet的使用和服务搭建
问题的由来 最近部门,在开发的时候遇到一个问题,现在有项目A B C三个项目,项目B和C分别提供了组件库由项目A直接引用.那么每次开打项目A获取最新后,同时还得打开项目B C获取最新然后编译一次.抛开 ...
- eclipse 配置Maven问题解决办法:新建maven工程时报错:Could not resolve archetype org.apache.maven.archetypes .
此文乃本作者配置maven,被其折磨n天,究极解决方案,好文要顶啊.欢迎致电: zhe-jiang.he@hp.com 首先各maven.archetypes下载地址: http://mirrors. ...
- Entity FrameWork 指导文章
Entity FrameWork学习指导: 转:http://www.entityframeworktutorial.net/code-first/configure-many-to-many-rel ...
- android 66 sharedperference的使用
package com.itheima.qqlogin; import java.io.BufferedReader; import java.io.File; import java.io.File ...
- Android - Binder驱动
以下资料摘录整理自老罗的Android之旅博客,是对老罗的博客关于Android底层原理的一个抽象的知识概括总结(如有错误欢迎指出)(侵删): http://blog.csdn.net/luosh ...
- tar命令解压、压缩gz/bz2/xz文件
1.处理.tar.gz 压缩:tar zcf FILE.tar.gz FILEDIR 解压:tar zxf FILE.tar.gz 2.处理.tar.bz2 压缩:tar jcf FILE.tar.b ...
- SQL Server中建立外键的方法
在SQL中建立外键约束,可以级联查询表中的数据,在C#代码生成器中,也能根据外键关系生成相应的外键表数据模型.外键也可防止删除有外键关系的记录,一定程度上保护了数据的安全性. 步骤: 1.要建立外键关 ...
- js实现FileUpload选择图片后预览功能
当asp.net的FileUpload选择一个图片后不需要上传就能显示出图片的预览功能, 代码: <%@ Page Language="C#" AutoEventWireup ...