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

Asteroids
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 12601   Accepted: 6849

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

 
【题解】:
  最大匹配最小顶点覆盖
 
【code】:
 /**
Judge Status:Accepted Memory:1880K
Time:16MS Language:G++
Code Lenght:1182B Author:cj
*/ #include<iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm> #define N 550
using namespace std; int n;
int map[N][N];
int cx[N],cy[N],mark[N]; int path(int u)
{
int j;
for(j=;j<=n;j++)
{
if(map[u][j]&&!mark[j])
{
mark[j]=;
if(cy[j]==-||path(cy[j]))
{
cx[u] = j;
cy[j] = u;
return ;
}
}
}
return ;
} int maxMatch()
{
memset(cx,-,sizeof(cx));
memset(cy,-,sizeof(cy));
int i;
int res = ;
for(i=;i<=n;i++)
{
if(cx[i]==-)
{
memset(mark,,sizeof(mark));
res+=path(i);
}
}
return res;
} int main()
{
int k,i;
scanf("%d%d",&n,&k);
memset(map,,sizeof(map));
for(i=;i<=k;i++)
{
int r,c;
scanf("%d%d",&r,&c);
map[r][c]=;
}
printf("%d\n",maxMatch());
return ;
}

poj 3041 Asteroids (最大匹配最小顶点覆盖——匈牙利模板题)的更多相关文章

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

    1.有一个n*n的矩阵,在矩阵上有k个行星,用武器射击一次可以消灭一行或者一列的行星,求消灭所有的行星的最少射击次数. 2.最小点覆盖数 = 最大匹配数 主要在于转化:看图: 这样,在建成的二分图中, ...

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

    题目链接:http://poj.org/problem?id=3041 在一个n*n的地图中,有m和障碍物,你每一次可以消除一行或者一列的障碍物,问你最少消除几次可以将障碍物全部清除. 用二分图将行( ...

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

    题意: N*N的矩阵,有K个敌人,坐标分别是(C1,C1),.....,(Rk,Ck). 有一个武器,每发射一次,可消掉某行或某列上的所有的敌人. 问消灭所有敌人最少需要多少发. 思路: 二分建图:左 ...

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

                                                                      Asteroids Time Limit: 1000MS   Mem ...

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

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

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

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

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

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

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

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

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

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

随机推荐

  1. java url中文 编译和解码

    js到servlet: js端 var minename='中文'; minename=encodeURI(encodeURI(minename)); java servlet 端 String na ...

  2. 移动平台的meta标签-----神奇的功效(转)

    对于桌面平台web布局中大家对meta标签再熟悉不过了,它永远位于 head 元素内部,对做SEO的朋友一定对meta有种特殊的感情吧,今天我们就来说说移动平台的meta标签,在移动平台meta标签究 ...

  3. saltstack实战2--远程执行之目标(target)

    target 就是目标的意思,你要在那台机器上执行此命令或此状态.或者说将此动作或者状态文件推送给谁来执行,让那个minion执行可以进行一些匹配 对于拥有大量机器的环境,如果单独一台台的执行指定mi ...

  4. Linux 命令 - scp: 远程文件拷贝

    scp 与普通的文件复制命令 cp 类似,而它们之间最大的差别在于 scp 命令的源或目标文件是远程文件. 命令格式 scp [options] [[user@]host1:]file1 ... [[ ...

  5. HDOJ2019数列有序!

    数列有序! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  6. sql常识-union

    SQL UNION 操作符 UNION 操作符用于合并两个或多个 SELECT 语句的结果集. 请注意,UNION 内部的 SELECT 语句必须拥有相同数量的列.列也必须拥有相似的数据类型.同时,每 ...

  7. SSRS 传多值参数问题

    SSRS报表参数是可单值或者多值.之前有个小伙伴问我,如果要传多值怎么传.然后我试了在各个参数之间,放换行符放逗号分号等都未能解决问题,最后想明白这个参数接受的应该是非字符类型,很大可能是数组,然后我 ...

  8. c++ 11 国标标准方面的异常处理与微软在Visual Studio 2012的异常处理的区别

    这段代码: __try { } __except(GetErrorCode()) { } 可以捕获空指针,但是包围在其中的代码不能有自带析构函数的对象.c++ 11 标准里面的auto_ptr关键字, ...

  9. jQuery 笔记

    1. 选择器  http://www.runoob.com/jquery/jquery-selectors.html 2. toggle()  用来切换 hide() 和 show() 方法   ht ...

  10. 169. Majority Element My Submissions Question

    Total Accepted: 95925 Total Submissions: 239241 Difficulty: Easy Given an array of size n, find the ...