POJ——T 3041 Asteroids
http://poj.org/problem?id=3041
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 23565 | Accepted: 12791 |
Description
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
* 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
Sample Input
3 4
1 1
1 3
2 2
3 2
Sample Output
2
Hint
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的更多相关文章
- poj 3041 Asteroids(最小点覆盖)
http://poj.org/problem?id=3041 Asteroids Time Limit: 1000MS Memory Limit: 65536K Total Submissions ...
- poj 3041 Asteroids (最大匹配最小顶点覆盖——匈牙利模板题)
http://poj.org/problem?id=3041 Asteroids Time Limit: 1000MS Memory Limit: 65536K Total Submissions ...
- POJ 3041 Asteroids / UESTC 253 Asteroids(二分图最大匹配,最小点匹配)
POJ 3041 Asteroids / UESTC 253 Asteroids(二分图最大匹配,最小点匹配) Description Bessie wants to navigate her spa ...
- POJ 3041 Asteroids (对偶性,二分图匹配)
题目:POJ 3041 Asteroids http://poj.org/problem?id=3041 分析: 把位置下标看出一条边,这显然是一个二分图最小顶点覆盖的问题,Hungary就好. 挑战 ...
- POJ 3041 Asteroids 二分图
原题连接:http://poj.org/problem?id=3041 Asteroids Time Limit: 1000MS Memory Limit: 65536K Total Submis ...
- poj 3041——Asteroids
poj 3041——Asteroids Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22604 Accep ...
- 二分图最大匹配(匈牙利算法) POJ 3041 Asteroids
题目传送门 /* 题意:每次能消灭一行或一列的障碍物,要求最少的次数. 匈牙利算法:把行和列看做两个集合,当有障碍物连接时连一条边,问题转换为最小点覆盖数==二分图最大匹配数 趣味入门:http:// ...
- POJ 3014:Asteroids(二分匹配,匈牙利算法)
id=3041">Asteroids Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 14399 Acce ...
- POJ 3041 Asteroids(模板——二分最大匹配(BFS增广))
题目链接: http://poj.org/problem?id=3041 Description Bessie wants to navigate her spaceship through a da ...
随机推荐
- Windows桌面美化
[工具链接]链接: https://pan.baidu.com/s/12aUGsu91F8WfaW5HU5ps3g 提取码: dnan [样例] [美化步骤] 1.解压下载文件,安装两个软件: Sta ...
- 题解 P3377 【【模板】左偏树(可并堆)】
所谓的左偏树,是一种可并堆的实现. 这种数据结构能够支持高效的堆合并,但是不支持查询节点等操作,因此不同于平衡树,它的结构是不平衡的. 左偏树满足如下两条基本性质: 1. 堆的性质 这也就是说左偏树每 ...
- MyBatis学习总结(7)——Mybatis缓存
一.MyBatis缓存介绍 正如大多数持久层框架一样,MyBatis 同样提供了一级缓存和二级缓存的支持 一级缓存: 基于PerpetualCache 的 HashMap本地缓存,其存储作用域为 Se ...
- Hbase读取数据
get命令和HTable类的get()方法用于从HBase表中读取数据.使用 get 命令,可以同时获取一行数据.它的语法如下: get ’<table name>’,’row1’ 下面的 ...
- mysql_5.6.24_winx64 安装
1.将zip压缩文件放在一个文件夹中 2.将路劲加入path环境变量 3.注册系统服务 在C:\windows下建立一个ini文件 1 2 3 4 5 6 7 8 9 10 11 12 [client ...
- Codeforces Round #286 (Div. 1) B. Mr. Kitayuta's Technology (强连通分量)
题目地址:http://codeforces.com/contest/506/problem/B 先用强连通判环.然后转化成无向图,找无向图连通块.若一个有n个点的块内有强连通环,那么须要n条边.即正 ...
- doT.js实现混合布局,判断,数组,函数使用,取模,数组嵌套
doT.js实现混合布局 数据结构 { "status": "1", "msg": "获取成功", "info ...
- elasticsearch index 之 put mapping
elasticsearch index 之 put mapping mapping机制使得elasticsearch索引数据变的更加灵活,近乎于no schema.mapping可以在建立索引时设 ...
- 自己定义CNN网络模型并使用caffe训练
caffe自带的例子中对mnist手写体数字训练使用的卷积神经网络是在lenet_train_test.prototxt中定义的,隐含层包含了2个卷积层,2个池化层,2个全连接层,1个激活函数层.网络 ...
- 解决linux ping: unknown host www.baidu.com
如果ping域名的时候出现ping:unknown host xxx.xxx 但是ping IP地址的时候可以通的话 可知是dns服务器没有配置好, 查看一下配置文件/etc/resolv.conf ...