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. HDU 2200 Eddy's AC难题

    解析: 1.可以从中任选m个人(n=>m>=2),有Cn(m)中选择; 2.再把这m个人分2组(每个人都要分组),要使满足最小ac数大于最大ac数,只需要在m个人中插板即可: 例如: m个 ...

  2. 使用nginx统一代理dashboard,grafana,Prometheus二级目录访问

    k8s上的这些管理工具必不可少,可以统一在nginx下的二级目录下. ingress是好,但我们不方便使用内部域名,相信么...:) 一,prometheus改造 在prometheus的deploy ...

  3. 【BZOJ】3456: 城市规划(多项式求ln)

    题解 在我写过分治NTT,多项式求逆之后 我又一次写了多项式求ln 我们定义一个数列的指数型生成函数为 \(\sum_{i = 0}^{n} \frac{A_{i}}{i!} x^{i}\) 然后这个 ...

  4. 牛客练习赛16 E - 求值

    题目大意: 链接:https://www.nowcoder.com/acm/contest/84/E 给定n个数字a1, a2, ..., an. 定义f(l, r) = al | al+1| ... ...

  5. 024 Yarn核心生态系统

    1.Yarn核心生态系统 2.Tez Tez是Apache最新的支持DAG作业的开源计算框架,它可以将多个有依赖的作业转换为一个作业从而大幅提升DAG作业的性能. 3.solo 全文检索 也可以部署在 ...

  6. 深入分析Spring Boot2,解决 java.lang.ArrayStoreException异常

    将某个项目从Spring Boot1升级Spring Boot2之后出现如下报错,查了很多不同的解决方法都没有解决: Spring boot2项目启动时遇到了异常: java.lang.ArraySt ...

  7. python scrapy 调试模式

    scrapy通过命令行创建工程,通过命令行启动爬虫,那么有没有方式可以在IDE中调试我们的爬虫呢? 实际上,scrapy是提供给我们工具的, 1. 首先在工程目录下新建一个脚本文件,作为我们执行爬虫的 ...

  8. [ 转载 ] Java中成员变量 和局部变量

    java语言支持的变量类型 类变量:独立于方法之外的变量,用 static 修饰. 局部变量:类的方法中的变量. 实例变量(全局变量):独立于方法之外的变量,不过没有 static 修饰. publi ...

  9. KNN与SVM对比&SVM与逻辑回归的对比

    首先说一下两种学习方式: lazy learning  和  eager learning. 先说 eager learning, 这种学习方式是指在进行某种判断(例如,确定一个点的分类或者回归中确定 ...

  10. Windows 7重启后USB 3.0无法使用的问题解决

    1.首先对主板USB3.0驱动程序进行重新安装 2.如果驱动程序重装后还是无法解决无法使用USB3.0设备的话,在win7桌面上找到“计算机”图标并鼠标右键,选择“管理”选项,找到设备管理器,然后找到 ...