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 ...
随机推荐
- JavaScript 数组方法和属性
一. 数组对象的操作方法 1. 数组的创建 2.prototype属性 返回对象原型的引用,prototype属性时object共有的. objectName.prototype,其中objectNa ...
- Spring学习笔记之BeanFactory
Spring bean container 的根接口,也是一个bean容器的基本功能,更深一步的接口像ListableBeanFactory 和 ConfigurableBeanFactory 都是 ...
- Browser GetImage
using Microsoft.Win32; using System; using System.ComponentModel; using System.Drawing; using System ...
- HTML5实战教程———开发一个简单漂亮的登录页面
最近看过几个基于HTML5开发的移动应用,比如臭名昭著的12036移动客户端就是主要使用HTML5来实现的,虽然还是有点反应迟钝,但已经比较流畅了,相信随着智能手机的配置越来越高性能越来越好,会越来越 ...
- 码表由来:ascll码-Gbk2312-GBK-Unicode-UTF-8
码表ascll码-Gbk2312-GBK-Unicode-UTF-8, ascll是基本的标准码表,GB2312是中文码表,GBK是扩展之后的码表,Unicode是国际通用码表,UTF-8是优化后的U ...
- EditTest输入类型设置
1,当输入为文字性密码时,输入前有提示效果,输入后有遮蔽效果 android:hint="@string/hint_etPassword" android:inputType=&q ...
- 程序员最爱 Mac、JS 是最热门技术
概况: 今年,有超过5万名开发者向我们分享了他们是谁,做什么工作,以及他们的成果.通过本文,你将看到有史以来最为全面的一次开发者情况调查的结果. 每8秒钟,就会有一位开发者在Stack Overflo ...
- hdoj-2025
#include "stdio.h"#include "string.h"void sort(char ch[],int count[],int n,int f ...
- UITableView全面解析,讲的好详细
--UIKit之UITableView 概述 在iOS开发中UITableView可以说是使用最广泛的控件,我们平时使用的软件中到处都可以看到它的影子,类似于微信.QQ.新浪微博等软件基本上随处都是U ...
- BZOJ 1968 约数研究
其实打个表就会发现,这个玩意儿是积性的,然后很happy的搞了一下. 不,不是这样. 考虑每个约数对答案的贡献,不难发现:约数i的贡献为n/i. 加之即可. #include<iostream& ...