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

Asteroids
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 14476   Accepted: 7880

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.
 

题目大意是导弹能够消灭直线上的障碍物,给出障碍物的位置,问最少须要多少导弹,把矩阵中的行放一边。列放还有一边,按二分图做,就不是非常难了,这一类的题目主要就是主函数那里有点不一样,其它套着模板来。

模板题

AC代码:

#include <stdio.h>
#include <string.h>
#define MAXN 510 int N,K,ans;
bool map[MAXN][MAXN];
int match[MAXN];
bool vis[MAXN]; bool find(int u)
{
int i;
for ( i=1; i<=N; i++)
{
if (map[u][i] && !vis[i] )
{
vis[i] = true;
if ( match[i] == -1 || find(match[i]) )
{
match[i] = u;
return true;
}
}
}
return false;
} int main()
{
int i,x,y;
ans = 0;
scanf("%d%d",&N,&K);
memset(map,0,sizeof(map));
memset(match,-1,sizeof(match));
for (i=0; i<K; i++)
{
scanf("%d%d",&x,&y);
map[x][y] = 1;
}
for (i=1; i<=N; i++)
{
memset(vis,0,sizeof(vis));
if (find(i))
ans++;
}
printf("%d\n",ans);
return 0;
}

poj 3041(最大匹配问题)的更多相关文章

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

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

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

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

  3. 二分图匹配 最大匹配数+最大点覆盖 POJ 1469+POJ 3041

    最大匹配数就等于最大点覆盖,因为在图里面,凡是要覆盖的点必定是连通的,而最大匹配之后,若还有点没有覆盖到,则必定有新的匹配,与最大匹配数矛盾,如果去掉一些匹配,则必定有点没有覆盖到. POJ 1469 ...

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

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

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

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

  6. poj 3041——Asteroids

    poj       3041——Asteroids Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22604   Accep ...

  7. Asteroids POJ - 3041

    Asteroids POJ - 3041 题目大意:N*N的地图里,存在一些小行星,Bessie有个很牛x但又很耗蓝的武器,一次可以消灭一行或者一列的所有小行星,问最少使用多少次这个武器可以消灭所有的 ...

  8. POJ 2226 Muddy Fields (最小点覆盖集,对比POJ 3041)

    题意 给出的是N*M的矩阵,同样是有障碍的格子,要求每次只能消除一行或一列中连续的格子,最少消除多少次可以全部清除. 思路 相当于POJ 3041升级版,不同之处在于这次不能一列一行全部消掉,那些非障 ...

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

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

随机推荐

  1. sonar Lint ----code bad smell

    类名注释报黄: 去掉这段黄做法:alt+enter 本文参考: http://www.cnblogs.com/xxoome/p/6677170.html

  2. 树链刨分(class版)

    class版树链剖(刨)分 感谢沙华大佬的赞助 其实没什么太大变化,就是用了几次一顿乱指... CODE: #include<iostream> #include<cstdio> ...

  3. 自己动手破解rar密码-ruby脚本实现

    破解密码,上策是社工的方式,下策则是暴力破解了.这里使用暴力破解,字典文件放在txt中:通过调用winrar的相关参数进行操作.经过测试,当字典中密码为100个时,破解耗时8秒(个人配置:i5-321 ...

  4. JavaScript——HashMap实现

    本文版权归博客园和作者吴双本人共同所有,转载和爬虫请注明原文链接博客园蜗牛 cnblogs.com\tdws . 首先提供一种获取hashCode的方法,是一种比较受欢迎的方式,该方法参照了一位园友的 ...

  5. 墨刀 vs Axure RP

    https://www.jianshu.com/p/b4b9c1f15304 墨刀https://modao.cc/ Axure RP https://www.axure.com/https://ww ...

  6. 【LOJ】#2181. 「SDOI2015」排序

    题解 还以为是啥毒瘤题 然后是个搜索题 复杂度算起来挺大 然后跑起来就连0.1ms不到= = 就是从大到小进行每种操作,搜出来一种操作就乘上一个操作数的阶乘就行 如果现在进行的操作操作\(2^i\)那 ...

  7. 配置Gitlab使用LDAP认证

    1. 通过SSH登陆Gitlab服务器. 2. 进行以下配置文件夹. [root@c720141 ~]# cd /etc/gitlab/ 3. 打开gitlab.rb配置文件,并加入以下配置. git ...

  8. 如何对手机使用adb

    因为要配合前端做测试,所以我需要在本机中安装adb驱动,以便可以连接手机进行各种操作. 好吧...装adb驱动这块当时我没有把流程给做记录...郁闷,下次再安装的时候再谷歌吧. 使用的简单脚本就是 有 ...

  9. 【Java】 大话数据结构(18) 排序算法(5) (直接插入排序)

    本文根据<大话数据结构>一书,实现了Java版的直接插入排序. 更多:数据结构与算法合集 基本概念 直接插入排序思路:类似扑克牌的排序过程,从左到右依次遍历,如果遇到一个数小于前一个数,则 ...

  10. [java] 数据处理

    背景: 有一组30天内的温度与时间的数据,格式如下: 详细情况:共30天的8k+项数据,每天内有260+项,每个记录温度的时间精确到秒 任务就是想根据这样的数据找到规律,来完成给定具体的时间预测出此时 ...