http://poj.org/problem?id=3041

Asteroids
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 17543   Accepted: 9548

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 <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#define INF 0x3f3f3f3f
#define N 510 int G[N][N], vis[N], used[N];
int n; bool Find(int u)
{
int i;
for(i = ; i <= n ; i++)
{
if(!vis[i] && G[u][i])
{
vis[i] = ;
if(!used[i] || Find(used[i]))
{
used[i] = u;
return true;
}
}
}
return false;
} int main()
{
int a, b, k, i, ans;
while(~scanf("%d%d", &n, &k))
{
ans = ;
memset(G, , sizeof(G));
while(k--)
{
scanf("%d%d", &a, &b);
G[a][b] = ;
}
memset(used, , sizeof(used));
for(i = ; i <= n ; i++)
{
memset(vis, , sizeof(vis));
if(Find(i))
ans++;
}
printf("%d\n", ans);
}
return ;
}

poj 3041 Asteroids(最小点覆盖)的更多相关文章

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

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

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

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

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

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

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

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

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

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

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

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

  7. POJ 3041(最小点覆盖)

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

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

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

  9. POJ 3041.Asteroids 最小顶点覆盖

    Asteroids Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22905   Accepted: 12421 Descr ...

随机推荐

  1. nodejs抓网易NBA数据

    var http = require("http");var cheerio = require("cheerio"); var url = "htt ...

  2. java6 新特新

    JAVA6新特性介绍   1. 使用JAXB来实现对象与XML之间的映射 JAXB是Java Architecture for XML Binding的缩写,可以将一个Java对象转变成为XML格式, ...

  3. maven常用构建命令

    mvn -v 查看maven版本 compile   编译项目 install   将项目加入到本地仓库中 clean   删除target test    测试 package     打包

  4. Drupal 7.31版本爆严重SQL注入漏洞

    今早有国外安全研究人员在Twitter上曝出了Drupal 7.31版本的最新SQL注入漏洞,并给出了利用测试的EXP代码. 在本地搭建Drupal7.31的环境,经过测试,发现该利用代码可成功执行并 ...

  5. Mysql的 时间戳转换 和 c# 的时间戳转换 (以秒来进行转换,非毫秒,主要是mysql不能存毫秒)

    Mysql 时间戳函数 => 从时间 转成 时间戳   UNIX_TIMESTAMP() 获取当前服务器时间的时间戳 UNIX_TIMESTAMP('2013-01-01 12:33:19') ...

  6. BMP图像格式

    BMP(全称Bitmap)是Window操作系统中的标准图像文件格式,可以分成两类:设备相关位图(DDB)和设备无关位图(DIB),使用非常广.它采用位映射存储格式,除了图像深度可选以外,不采用其他任 ...

  7. hdu 3496 Watch The Movie

    题意:题目给定N部电影,每部电影有时长和价值,要求看M部电影,并且时间控制在L以内,转化为背包问题,让我们在N件物品中找正好M件物品塞进容量L的包中,求最大的价值.// dp[i][j] 表示在容量为 ...

  8. Hibernate向MySQL插入中文数据--乱码解决

    <property name="hibernate.connection.url">jdbc:mysql://127.0.0.1:3306/exam?useUnicod ...

  9. xcode升级,报错 libxml/tree.h not found (Xcode4.6解决方案)

    转:http://blog.csdn.net/yangxuanlun/article/details/8639075 Xcode升级到4.6以后,他妈的,libxml/tree.h找不到了,搞了大半天 ...

  10. 【转】STL空间配置器

    STL空间配置器(allocator)在所有容器内部默默工作,负责空间的配置和回收.STL标准为空间配置器定义了标准接口(可见<STL源码剖析>P43).而具体实现细节则由各编译器实现版本 ...