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

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 23565   Accepted: 12791

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

 
拆点成边。
最小点覆盖数==最大匹配数
 #include <cstring>
#include <cstdio> using namespace std; int n,m,u,v,ans,match[];
int map[][];
bool vis[]; bool find(int u)
{
for(int v=;v<=n;v++)
if(map[u][v]&&!vis[v])
{
vis[v]=;
if(!match[v]||find(match[v]))
{
match[v]=u;
return true;
}
}
return false;
} int main()
{
scanf("%d%d",&n,&m);
for(int i=;i<=m;i++)
{
scanf("%d%d",&u,&v);
map[u][v]=;
}
for(int i=;i<=n;i++)
{
memset(vis,,sizeof(vis));
if(find(i)) ans++;
}
printf("%d\n",ans);
return ;
}

POJ——T 3041 Asteroids的更多相关文章

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

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

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

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

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

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

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

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

  5. POJ 3041 Asteroids 二分图

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

  6. poj 3041——Asteroids

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

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

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

  8. POJ 3014:Asteroids(二分匹配,匈牙利算法)

    id=3041">Asteroids Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 14399   Acce ...

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

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

随机推荐

  1. Vue中的坑

    今天给大家总结了Vue中的坑,都是平常踩到的,希望对大家有所帮助 1.vuex的一个“坑” 报错原因:在使用Vuex的时候在main.js中引入的时候对名字的大小写有区别 解决法案: 错误写法: 正确 ...

  2. dataTable 动态列 二次加载

    需要把 列头和表格内容全部清空 if ($('#datatable').hasClass('dataTable')) { var dttable = $('#datatable').dataTable ...

  3. Nginx监控

    http://www.ttlsa.com/nginx/nginx-status-detail/ http://blog.csdn.net/bobpen/article/details/53431699 ...

  4. ASP.NET-HTML.Helper常用方法

    Html.ActionLink方法 Html.ActionLink("linkText","actionName") Html.ActionLink(" ...

  5. 面试书上一些题目的整理:O(n)复杂度排序年龄 & 青蛙跳台阶

    可以按照年龄的个数,设置99个桶,然后桶内处理. 青蛙跳台阶,每次1阶或者2阶,就是fib数 如果每次1到n阶,那么归纳法可得,是2^(n-1) 另外1*2 覆盖 2*n个矩阵的问题,仍然是Fib数. ...

  6. linux gnome kde点滴

    2014.12.08 下面切换的方法对于fedora 17没有效果,对于fedora 17, 要使用system-switch-displaymanager,出现 点击相应的选项,然后就进入相应的启动 ...

  7. C++ STL 源代码学习(之deque篇)

    stl_deque.h /** Class invariants: * For any nonsingular iterator i: * i.node is the address of an el ...

  8. 30个php操作redis经常用法代码样例

    这篇文章主要介绍了30个php操作redis经常用法代码样例,本文事实上不止30个方法,能够操作string类型.list类型和set类型的数据,须要的朋友能够參考下 redis的操作非常多的,曾经看 ...

  9. Transformation in kentico

    https://docs.kentico.com/k10/developing-websites/loading-and-displaying-data-on-websites/writing-tra ...

  10. [JZOJ5166] [NOIP2017模拟6.26卢学魔] 解题报告 (记忆化搜索|拓扑排序)

    题目链接: http://172.16.0.132/senior/#main/show/5166 题目: 题解: 这个没什么好讲的,就是注意生产者没人吃也不是食物链,这告诉我们要积累生物知识注意细节 ...