poj       3041——Asteroids
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 22604   Accepted: 12247

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

Source

题目大意
给你一个N*N的矩阵,有一些格子里有小行星,现在Bessie有一些威力很大的炮弹,每一次射击都能够消灭掉矩阵中一行或一列的小行星,
但是炮弹很贵,问你需要消灭掉所有小行星所需的最小炮弹数目。
思路:
这道题和上一道题的思路是一样的,我们只需要将每一行和每一列都当做是二分图的一个集合,然后在进行二分图匹配。
这道题就是一个裸的求最小点覆盖的题。在二分图中,最小点覆盖=最大匹配数。so,着我们就直接求最大匹配数就好了。
代码:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define N 550
using namespace std;
bool vis[N];
int n,m,x,y,ans,pre[N],map[N][N];
int read()
{
    ,f=;char ch=getchar();
    ; ch=getchar();}
    +ch-'; ch=getchar();}
    return x*f;
}
int find(int x)
{
    ;i<=n;i++)
     if(!vis[i]&&map[x][i])
     {
         vis[i]=true;
         if(!pre[i]||find(pre[i]))
         {
             pre[i]=x;
             ;
         }
     }
     ;
}
int main()
{
    n=read(),m=read();
    ;i<=m;i++)
     x=read(),y=read(),map[x][y]=;
    ;i<=n;i++)
     {
         memset(vis,,sizeof(vis));
         if(find(i)) ans++;
     }
    printf("%d",ans);
    ;
}



poj 3041——Asteroids的更多相关文章

  1. POJ 3041 Asteroids / UESTC 253 Asteroids(二分图最大匹配,最小点匹配)

    POJ 3041 Asteroids / UESTC 253 Asteroids(二分图最大匹配,最小点匹配) Description Bessie wants to navigate her spa ...

  2. POJ 3041 Asteroids (对偶性,二分图匹配)

    题目:POJ 3041 Asteroids http://poj.org/problem?id=3041 分析: 把位置下标看出一条边,这显然是一个二分图最小顶点覆盖的问题,Hungary就好. 挑战 ...

  3. 二分图最大匹配(匈牙利算法) POJ 3041 Asteroids

    题目传送门 /* 题意:每次能消灭一行或一列的障碍物,要求最少的次数. 匈牙利算法:把行和列看做两个集合,当有障碍物连接时连一条边,问题转换为最小点覆盖数==二分图最大匹配数 趣味入门:http:// ...

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

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

  5. poj 3041 Asteroids (最大匹配最小顶点覆盖——匈牙利模板题)

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

  6. POJ 3041 Asteroids 二分图

    原题连接:http://poj.org/problem?id=3041 Asteroids Time Limit: 1000MS   Memory Limit: 65536K Total Submis ...

  7. POJ 3041 Asteroids(模板——二分最大匹配(BFS增广))

    题目链接: http://poj.org/problem?id=3041 Description Bessie wants to navigate her spaceship through a da ...

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

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

  9. POJ 3041 Asteroids 匈牙利算法,最大流解法,行列为点 难度:1

    http://poj.org/problem?id=3041 #include <cstdio> #include <cstring> #include <vector& ...

随机推荐

  1. codevs 2761 脏话过滤

    时间限制: 1 s  空间限制: 8000 KB  题目等级 : 白银 Silver   题目描述 Description 某论坛希望打造文明论坛,对于每个帖子需要将脏话换成*输出. 脏话有38,25 ...

  2. 使用Eclipse进行PHP的服务器端调试

    最近工作需要对PHP的服务器端代码进行远程调试,涉及到Eclipse里环境的设置.在网上找了很多资料,大多不全,或者缺少配图,于是把自己做的过程中遇到的问题记录了下来,希望对需要的朋友们有所帮助. 首 ...

  3. VBA Promming——入门教程

    VBA Visual Basic for Applications(VBA)是Visual Basic的一种宏语言,是微软开发出来在其桌面应用程序中执行通用的自动化(OLE)任务的编程语言.主要能用来 ...

  4. 网新恩普(W 笔试)

    选择题 1.一桶有黄色,绿色,红色三种,闭上眼睛抓取同种颜色的两个.抓取多少个就可以确定你肯定有两个同一颜色的球? 答案: 4次 1.最坏打算抓3次都是不同颜色的黄.绿.红,此时,三种颜色的球各抓了一 ...

  5. uva1627 Team them up!

    注意这题要求互相认识不认识的人之间连一条线一个人在组1,那么不认识(互相认识)的人就在组0:同时这些人不认识的人就在组1.每个联通分量都可以独立推导,遇到矛盾则无解一个联通分量有一个核心,其他的点是分 ...

  6. navicat 链接数据库查看的工具 可以同时查看各种数据库 MySql SqlServer

    navicat 链接数据库查看的工具 Navicat_Premium_10.0.11.0_XiaZaiBa

  7. 清空表单方法 清空变量 iview modal

    方法一 通过json序列号和反序列号 清空一次数据 数据需要copy出来一份 orgFormClearAllInput () { this.$refs.n1.formValidate = JSON.p ...

  8. QT_3

    1.QT中命名的规范和常用的快捷键 1.1 命名规范: 类名:首字母大写    多个单词时单词与单词之间首 字母大写 函数名:变量名称   首字母小写    多个单词时,单词和单词之间首字母大写 1. ...

  9. mean shift博客推荐

    https://blog.csdn.net/maweifei/article/details/78766784 https://blog.csdn.net/gdfsg/article/details/ ...

  10. Vickers Vane Pump - How To Choose Vane Pump Parameter Specifications?

    1 rated pressure selection. The rated pressure of the vane pump products is 7MPa, 1OMPa, 16MPa, 2lMP ...