POJ 3041 Asteroids(最小点覆盖集)
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 20748 | Accepted: 11278 |
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 <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <queue>
#include <vector>
#define inf 0x7fffffff
#define met(a,b) memset(a,b,sizeof a)
typedef long long ll;
using namespace std;
const int N = ;
const int M = ;
int read() {
int x=,f=;
char c=getchar();
while(c<''||c>'') {
if(c=='-')f=-;
c=getchar();
}
while(c>=''&&c<='') {
x=x*+c-'';
c=getchar();
}
return x*f;
}
int n1,n2,k;
int mp[N][N],vis[N],link[N];
int dfs(int x) {
for(int i=; i<=n2; i++) {
if(mp[x][i]&&!vis[i]) {
vis[i]=;
if(link[i]==-||dfs(link[i])) {
link[i]=x;
return ;
}
}
}
return ;
} int main()
{
int cas ;
int s=;
scanf("%d%d",&n1,&k);
met(mp,);n2=n1;
int xx,yy;
for(int i=; i<k; i++) {
scanf("%d%d",&xx,&yy);
mp[xx][yy]=;
}
memset(link,-,sizeof(link));
for(int i=; i<=n1; i++) {
memset(vis,,sizeof(vis));
if(dfs(i)) s++;
}
printf("%d\n",s);
return ;
}
POJ 3041 Asteroids(最小点覆盖集)的更多相关文章
- 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(最小点覆盖)
http://poj.org/problem?id=3041 Asteroids Time Limit: 1000MS Memory Limit: 65536K Total Submissions ...
- 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 最小点覆盖 == 二分图的最大匹配
Description Bessie wants to navigate her spaceship through a dangerous asteroid field in the shape o ...
- Asteroids POJ - 3041 二分图最小点覆盖
Asteroids POJ - 3041 Bessie wants to navigate her spaceship through a dangerous asteroid field in ...
- POJ 3041(最小点覆盖)
题意: 假如你如今正处在一个N*N的矩阵中,这个矩阵里面有K个障碍物,你拥有一把武器,一发弹药一次能消灭一行或一列的障碍物,求最小的弹药消灭所有障碍物 输入为: N K 接下来有K行,每行包括 ...
- PKU 3041 Asteroids 最小点覆盖(最大匹配模板题)
题目大意:给你一个N*N的矩阵, 里面有K个星球, 我们可以让武器攻击矩阵的一行或者一列来使得这个星球被击碎, 现在问你最少需要几个这种武器才能把所有的星球击碎? 解题思路:关键是建模构图 把每一行当 ...
- Strategic game POJ - 1463 【最小点覆盖集】
Bob enjoys playing computer games, especially strategic games, but sometimes he cannot find the solu ...
随机推荐
- C#操作Access数据库(创建&修改结构)
本文转自:http://www.cnblogs.com/liyugang/archive/2012/11/17/2775393.html 想要在程序中控制Access,不是数据,而是Access数据库 ...
- 端午小长假--前端基础学起来04CSS选择器
定义: 选择器{ 样式: } 选择器指明{}中的样式的作用对象,即作用于网页中的哪些元素 <head><meta http-equiv="Content-Type" ...
- Python应用与实践
http://www.cnblogs.com/skynet/archive/2013/05/06/3063245.html
- 深入理解dispatch_queue
Grand Central Dispatch是苹果过去几年创造出来的非常强大的API,在Let's Build系列的最新一期中,我们将探究dispatch_queue基础功能的重新实现.该主题是Rob ...
- 关于BIOS的一点东西
关于BIOS的一点东西 编辑删除转载2016-05-20 00:36:36 去把BIOS的每个单词意思都有道一遍就都明白了,BOOT是更改 启动顺序的(台式机一直按del键就会进入BIOS界面,用上下 ...
- [网络技术][转]PPTP协议解析
PPTP协议大体上可以分为两部分:控制层连接和隧道,下面简要介绍两部分的功能.如果要详细了解PPTP协议请阅读RFC文档. 一. Control Connection Protol 控制层连接是基于T ...
- object_c函数多个返回值
- (void)readStr1:(NSString**)str1 andStr2:(NSString**)str2{ NSString *s1 = @"1"; NSS ...
- Form表单的操作
form对象 <form name=“form1” action=“login.php” method=“post”></form> form对象的属性 name:表单名称 m ...
- 分析一个嵌入payload的恶意.lnk文件
原文:https://isc.sans.edu/diary/Analyzis+of+a+Malicious+.lnk+File+with+an+Embedded+Payload/20763 We re ...
- 解决win7资源监视器不能开启
刚开始时是这样,点击开始监控,无效 需要开始服务即可解决