Asteroids
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 18289   Accepted: 9968

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).

解题思路:

http://www.cnblogs.com/lyy289065406/archive/2011/07/30/2121730.html

把方阵看做一个特殊的二分图(以行列分别作为两个顶点集V1、V2,其中| V1|=| V2|)

然后把每行x或者每列y看成一个点,而障碍物(x,y)可以看做连接x和y的边。按照这种思路构图后。问题就转化成为选择最少的一些点(x或y),使得从这些点与所有的边相邻,其实这就是最小点覆盖问题。

关键是构图,有点抽象,需要把点当成是边。

再利用二分图最大匹配的König定理:

最小点覆盖数 = 最大匹配数

 

(PS:最小点覆盖:假如选了一个点就相当于覆盖了以它为端点的所有边,你需要选择最少的点来覆盖图的所有的边。)

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std;
const int MAX = + ;
int g[MAX][MAX],link[MAX],vis[MAX];
int n,V1,V2,k;
int dfs(int x)
{
for(int i = ; i <= V2; i++)
{
if(vis[i] == && g[x][i])
{
vis[i] = ;
if(link[i] == || dfs(link[i]))
{
link[i] = x;
return true;
}
}
}
return false;
}
int main()
{
scanf("%d%d", &n,&k);
V2 = V1 = n;
for(int i = ; i <= k; i++)
{
int x,y;
scanf("%d%d",&x,&y);
g[x][y] = true; }
int m = ;
memset(link,,sizeof(link));
for(int i = ; i <= V1; i++)
{
memset(vis,,sizeof(vis));
if(dfs(i))
m++;
}
printf("%d\n",m);
return ;
}

POJ3041Asteroids(最小点覆盖+有点小抽象)的更多相关文章

  1. 【最小点覆盖】POJ3041-Asteroids

    [题目大意] 在n*n的网格上有n个点,每次删除一行或者一列,问至少要删除几次才能删除完全部的这些店? [思路] 在国庆最后一天到来前,把二分图的三个基本情况[最小点覆盖][DAG图的最小路径覆盖]和 ...

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

    每次选择清除一行或者一列上的小行星.最少选择几次. 将行和列抽象成点,第i行为节点i+n,第j列为节点j,每个行星则是一条边,连接了所在的行列. 于是问题转化成最小点覆盖.二分图的最小点覆盖==最大匹 ...

  3. 【noip模拟】最小点覆盖

    Time Limit: 1000ms      Memory Limit: 128MB Description 最小点覆盖是指在二分图中,用最小的点集覆盖所有的边.当然,一个二分图的最小点覆盖可能有很 ...

  4. Ex 6_21 最小点覆盖问题_第八次作业

    子问题定义: 对于图中的每个结点,有两种状态,即属于最小点覆盖和不属于最小点覆盖,定义minSet[i][0]表示结点i属于点覆盖,并且以i为根的树的最小点覆盖的大小.minSet[i][1]表示点i ...

  5. POJ 3041 Asteroids(最小点覆盖)题解

    题意:n*n的网格中有k个点,开一枪能摧毁一行或一列的所有点,问最少开几枪 思路:我们把网格看成两个集合,行集合和列集合,如果有点x,y那么就连接x->y,所以我们只要做最小点覆盖就好了. 参考 ...

  6. 二分图 最小点覆盖 poj 3041

    题目链接:Asteroids - POJ 3041 - Virtual Judge  https://vjudge.net/problem/POJ-3041 第一行输入一个n和一个m表示在n*n的网格 ...

  7. [BZOJ3140][HNOI2013]消毒(二分图最小点覆盖)

    3140: [Hnoi2013]消毒 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1621  Solved: 676[Submit][Status] ...

  8. nyoj237 游戏高手的烦恼(最小点覆盖)

    题目237 题目信息 pid=237" style="text-decoration:none; color:rgb(55,119,188)">执行结果 本题排行 ...

  9. Cogs 1632. 搬运工(二分图最小点覆盖)

    搬运工 ★ 输入文件:worker.in 输出文件:worker.out 简单对比 时间限制:1 s 内存限制:256 MB [题目描述] 小涵向小宇推荐了一款小游戏. 游戏是这样的,在一个n*n的地 ...

随机推荐

  1. ssh相关操作

    连接:ssh username@ip 拷贝ssh客户端文件到ssh服务器: cp 文件名 username@ip:文件名 拷贝ssh服务器文件夹到ssh客户端: scp -r wanglianghe@ ...

  2. vrrp两用

    早上想了想vrrp的使用,1,网关冗余 2,服务器热备 思想稍微有点不一样.主要在于监控口 服务器的话有心跳线,用户同步一些配置和迁移一些服务.达到热备的目的.:牵涉到四个优先级:建议这样排序: 主机 ...

  3. [MetaHook] Quake Bink function

    If you want to play Bink video in game, maybe you need this code. QBink.h #ifndef QBINK_H #define QB ...

  4. iOS中UIMenuController的使用

    不知你有没有发现,在你的微信朋友中,长按一段文字(正文或者评论),会弹出这样子的玩意: 要想在你的view或者viewController中实现长按弹出菜单栏你必须要调用becomeFirstResp ...

  5. JqueryEasyUI教程入门篇

    什么是jQueryEasyUI? JqueryUI是一组基于jQuery的UI插件集合 学习jQueryEasyUI的条件? 必须掌握Jquery的基本语法知识 jQueryEasyUI的特点? 1. ...

  6. Orchard 刨析:前奏曲

    Orchard中大量使用了依赖注入,而实现依赖注入的组件就是Autofac,它在Orchard中扮演者非常重要的角色,多租户如是,模块如是,工作区也如是.今天就来讲讲Autofac在Orchard中的 ...

  7. xcode更新,想想也是醉了

    每次更新,都要整个文件全部更新,这下载速度,想想也是醉了,苹果你就不能搞了更新包吗!!

  8. Javascript基础系列之(七)函数(定义和调运函数)

    函数是一个可以随时运行的语句,简单说,函数是完成某个功能的一组语句,它接受0或者多个参数. 函数的基本语法如下 function functionName([arg0,arg1,......argN] ...

  9. jQuery理解之(二)功能函数

    在javascript编程中,开发者通常需要编写很多小程序来实现一些特定的功能.例如浏览器检测,字符串处理.数组的编辑等.jQuery对这些常用的程序进行了总结,提供了很多实用的函数. 1.检测浏览器 ...

  10. 转:java多线程--同步容器

    java同步容器 在Java的集合容器框架中,主要有四大类别:List.Set.Queue.Map.List.Set.Queue接口分别继承了Collection接口,Map本身是一个接口.注意Col ...