Asteroids
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 20748   Accepted: 11278

Description

Bessie wants to navigate her spaceship through a dangerous asteroid field in the shape of an N x N grid (1 <= N <= 500). The grid contains K asteroids (1 <= K <= 10,000), which are conveniently located at the lattice points of the grid.

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

* Line 1: Two integers N and K, separated by a single space.

* 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

* Line 1: The integer representing the minimum number of times Bessie must shoot.

Sample Input

3 4
1 1
1 3
2 2
3 2

Sample Output

2

Hint

INPUT DETAILS:
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(最小点覆盖集)的更多相关文章

  1. POJ 3041 Asteroids (最小点覆盖集)

    题意 给出一个N*N的矩阵,有些格子上有障碍,要求每次消除一行或者一列的障碍,最少消除多少次可以全部清除障碍. 思路 把关键点取出来:一个障碍至少需要被它的行或者列中的一个消除. 也许是最近在做二分图 ...

  2. Asteroids POJ - 3041 【最小点覆盖集】

    Bessie wants to navigate her spaceship through a dangerous asteroid field in the shape of an N x N g ...

  3. poj 3041 Asteroids(最小点覆盖)

    http://poj.org/problem?id=3041 Asteroids Time Limit: 1000MS   Memory Limit: 65536K Total Submissions ...

  4. poj 3041 Asteroids 最小点覆盖/最大匹配

    Asteroids Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16242 Accepted: 8833 Descriptio ...

  5. [poj] 3041 Asteroids || 最小点覆盖=最大二分图匹配

    原题 本题为最小点覆盖,而最小点覆盖=最大二分图匹配 //最小点覆盖:用最少的点(左右两边集合的点)让每条边都至少和其中一个点关联. #include<cstdio> #include&l ...

  6. POJ 3041 Asteroids 最小点覆盖 == 二分图的最大匹配

    Description Bessie wants to navigate her spaceship through a dangerous asteroid field in the shape o ...

  7. Asteroids POJ - 3041 二分图最小点覆盖

       Asteroids POJ - 3041 Bessie wants to navigate her spaceship through a dangerous asteroid field in ...

  8. POJ 3041(最小点覆盖)

    题意: 假如你如今正处在一个N*N的矩阵中,这个矩阵里面有K个障碍物,你拥有一把武器,一发弹药一次能消灭一行或一列的障碍物,求最小的弹药消灭所有障碍物 输入为:     N K 接下来有K行,每行包括 ...

  9. PKU 3041 Asteroids 最小点覆盖(最大匹配模板题)

    题目大意:给你一个N*N的矩阵, 里面有K个星球, 我们可以让武器攻击矩阵的一行或者一列来使得这个星球被击碎, 现在问你最少需要几个这种武器才能把所有的星球击碎? 解题思路:关键是建模构图 把每一行当 ...

  10. Strategic game POJ - 1463 【最小点覆盖集】

    Bob enjoys playing computer games, especially strategic games, but sometimes he cannot find the solu ...

随机推荐

  1. plist 和 Xib

    plist文件 mainbudin加载时候有后缀 xib文件  mainbudin加载时候无需后缀

  2. Spring学习笔记之整合struts

    1.现有项目是通过 <action    path="/aaaaAction"                type="org.springframework.w ...

  3. android webview实战

    webSettings = wvShowProduce.getSettings();//设置WebView属性,能够执行Javascript脚本webSettings.setJavaScriptEna ...

  4. Line计划今年全面进军中国市场:建立本地团队

    北京时间6月13日下午消息,<华尔街日报>报道称,移动消息应用Line计划于今年晚些时候进军中国市场.Line将在中国建立本地团队,开发内容和功能,从而进一步开拓中国这一全球最大的移动市场 ...

  5. HTML--1标签表格

    HTML   内容(Hyper Text Markup Language,超文本标记语言) CSS    网页美化 Javascript    脚本语言 打开DREAMWEAVER,新建HTML,如下 ...

  6. 2013年7月份第2周51Aspx源码发布详情

    FineOffice自动化办公(OA)源码  2013-7-12 [ VS2010 ]源码描述:此源码使用fineui开发,作为村居使用的系统,所以命名为fineoffice,其实你在此基础上扩成CR ...

  7. Logger.getLogger()和 LogFactory.getLog()

    Logger.getLogger()和LogFactory.getLog()的区别:    1.Logger.getLogger()是使用log4j的方式记录日志:2.LogFactory.getLo ...

  8. matlab求曲线长度

    曲线段在上的弧长为采用积分所求弧长s=∫√(1+y'²)dxmatlab求出各点的导数,然后按照上式积分 clear>> x=1:0.1:10;>> y=rand(1,leng ...

  9. Manacher算法 , 实例 详解 . NYOJ 最长回文

    51 Nod http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1089 Manacher 算法 定义数组 p[i]表示以i为 ...

  10. vi中的批量替换

    举个例子啊: 将文件tihuan(假设此文本中字符a)中的所有字符a换成字符w,其命令为: 1.vi tihuan 2.按esc键 3.按shift+: 4.在:后输入    %s/a/w/g 就ok ...