Asteroids
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 18183   Accepted: 9905

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.
题解:
题意就是说,一个飞船在飞,N*N的网格里面有障碍,一个子弹可以打穿一行或者一列,让找消除所有障碍的最小子弹
代码:
 #include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#define mem(x,y) memset(x,y,sizeof(x))
using namespace std;
const int INF=0x3f3f3f3f;
const int MAXN=;
vector<int>vec[MAXN];
int usd[MAXN],vis[MAXN];
bool dfs(int x){
for(int i=;i<vec[x].size();i++){
int v=vec[x][i];
if(!vis[v]){
vis[v]=;
if(usd[v]==-||dfs(usd[v])){
usd[v]=x;return true;
}
}
}
return false;
}
int main(){
int N,K,R,C;
while(~scanf("%d%d",&N,&K)){
mem(vis,);mem(usd,-);
for(int i=;i<=N;i++)vec[i].clear();
while(K--){
scanf("%d%d",&R,&C);
vec[R].push_back(C);
}
int ans=;
for(int i=;i<=N;i++){
mem(vis,);
if(dfs(i))ans++;
}
printf("%d\n",ans);
}
return ;
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  8. POJ3041 Asteroids(二分图最小点覆盖)

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

  9. POJ 3041 Asteroids (二分图最小点覆盖集)

    Asteroids Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 24789   Accepted: 13439 Descr ...

随机推荐

  1. Problem E: Product

    Problem E: ProductTime Limit: 1 Sec Memory Limit: 128 MBSubmit: 18 Solved: 14[Submit][Status][Web Bo ...

  2. BZOJ 1601: [Usaco2008 Oct]灌水( MST )

    MST , kruskal 直接跑 ---------------------------------------------------------------------- #include< ...

  3. ssma for oracle

    SQL Server Migration Assistant (SSMA) for Oracle lets you quickly convert Oracle database schemas to ...

  4. [LeetCode]题解(python):006-ZigZag Conversion

    题目来源: https://leetcode.com/problems/zigzag-conversion/ 题意分析: 这道题目是字符串处理的题目.输入一个字符串和一个数字,将字符串填入倒Z形输入字 ...

  5. BeanUtils复制属性

    package xiao; public class User2 { private String name; private String password; public String getNa ...

  6. Myeclipse安装Activiti

    1.将压缩包内activiti文件夹放入Myeclipse\dropins文件夹内并修改activiti文件夹内Link文件指向自己的目录重启Myeclipse(这时打开bpmn文件仍会报错).2.将 ...

  7. Lotus Sametime

    编辑 Lotus Sametime属于IBM旗下的Lotus软件,包括一个成熟的协作平台提供商. 外文名 Lotus Sametime 属    于 IBM旗下的Lotus软件 包    括 一个成熟 ...

  8. Ants(思维)

    Ants Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 12893   Accepted: 5637 Description ...

  9. mahout贝叶斯算法开发思路(拓展篇)2

    如果想直接下面算法调用包,可以直接在mahout贝叶斯算法拓展下载,该算法调用的方式如下: $HADOOP_HOME/bin hadoop jar mahout.jar mahout.fansy.ba ...

  10. 深入理解java嵌套类和内部类

    一.什么是嵌套类及内部类 能够在一个类的内部定义还有一个类.这样的类称为嵌套类(nested classes),它有两种类型:静态嵌套类和非静态嵌套类.静态嵌套类使用非常少,最重要的是非静态嵌套类,也 ...