poj 3041 Asteroids 最小点覆盖/最大匹配
Asteroids
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 16242 Accepted: 8833
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).
题意
给你一个n*n的方阵,然后有一些东西在一些坐标上,你需要用最少的炸弹把这些东西都炸掉,然后问你,最少炸弹数量是多少
题解
我们建立一个二分图,然后把每行当成一个点,把每列当成一个点,如果这一行这一列有炸弹的话,我们就建一条边。那么这道题,就转化成了,最小点覆盖问题,直接跑一大最大匹配就好了
总而言之,言而总之,我也是套版做的= =
代码
#define REP(i, n) for (int i=0;i<n;++i)
#define RD(n) scanf("%d",&n)
int V;
vector<int> G[maxn];
int match[maxn];
int used[maxn];
void add_edge(int u,int v)
{
G[u].push_back(v);
G[v].push_back(u);
}
bool dfs(int v)
{
used[v]=1;
for(int i=0;i<G[v].size();i++)
{
int u=G[v][i],w=match[u];
if(w<0||!used[w]&&dfs(w))
{
match[v]=u;
match[u]=v;
return 1;
}
}
return 0;
}
int bipartite_matching()
{
int res=0;
memset(match,-1,sizeof(match));
for(int v=0;v<V;v++)
{
if(match[v]<0)
{
memset(used,0,sizeof(used));
if(dfs(v))
res++;
}
}
return res;
}
int n,k;
int R[maxn],C[maxn];
void solve()
{
V=n*2;
for(int i=0;i<k;i++)
{
add_edge(R[i]-1,n+C[i]-1);
}
printf("%d\n",bipartite_matching());
}
int main()
{
scanf("%d%d",&n,&k);
REP(i,k)
{
RD(R[i]);
RD(C[i]);
}
solve();
return 0;
}
poj 3041 Asteroids 最小点覆盖/最大匹配的更多相关文章
- poj 3041 Asteroids(最小点覆盖)
http://poj.org/problem?id=3041 Asteroids Time Limit: 1000MS Memory Limit: 65536K Total Submissions ...
- POJ 3041 Asteroids (最小点覆盖集)
题意 给出一个N*N的矩阵,有些格子上有障碍,要求每次消除一行或者一列的障碍,最少消除多少次可以全部清除障碍. 思路 把关键点取出来:一个障碍至少需要被它的行或者列中的一个消除. 也许是最近在做二分图 ...
- [poj] 3041 Asteroids || 最小点覆盖=最大二分图匹配
原题 本题为最小点覆盖,而最小点覆盖=最大二分图匹配 //最小点覆盖:用最少的点(左右两边集合的点)让每条边都至少和其中一个点关联. #include<cstdio> #include&l ...
- POJ 3041 Asteroids 最小点覆盖 == 二分图的最大匹配
Description Bessie wants to navigate her spaceship through a dangerous asteroid field in the shape o ...
- Asteroids POJ - 3041 二分图最小点覆盖
Asteroids POJ - 3041 Bessie wants to navigate her spaceship through a dangerous asteroid field in ...
- Asteroids POJ - 3041 【最小点覆盖集】
Bessie wants to navigate her spaceship through a dangerous asteroid field in the shape of an N x N g ...
- poj 3041 Asteroids (二分图的最大匹配 第一题)
题目:http://poj.org/problem?id=3041 题意:在某个n*n的空间内,分布有一些小行星,某人在里面打炮,放一枪后某一行或某一列的行星就都没了,让求最少的打炮数. 然后把每行x ...
- POJ 3041 Asteroids 最小覆盖数
http://poj.org/problem?id=3041 题目大意: 一辆宇宙飞船在一个小行星带中,你知道,这很危险.他有一种武器,可以清除掉一行或一列的小行星.问把小行星全部清除最少的武器使用次 ...
- POJ 3041(最小点覆盖)
题意: 假如你如今正处在一个N*N的矩阵中,这个矩阵里面有K个障碍物,你拥有一把武器,一发弹药一次能消灭一行或一列的障碍物,求最小的弹药消灭所有障碍物 输入为: N K 接下来有K行,每行包括 ...
随机推荐
- YUV422(UYVY)转RGB565源代码及其讲解.md
目录 前言 源码 代码分析 YUV三个分量的关系 循环遍历 结束语 前言 使用zmm220核心板,IFACE102版本的内核等,4300型号的LCD,XC7011_SC1145摄像头,亲测有效. 本文 ...
- mysql命令gruop by报错this is incompatible with sql_mode=only_full_group_by
在mysql 工具 搜索或者插入数据时报下面错误: ERROR 1055 (42000): Expression #1 of SELECT list is not in GROUP BY clause ...
- 缓存数据库-redis安装和配置
一:redis安装 python操作redis分为两部分,一为安装redis程序 二是安装支持python操作redis的模块 1)安装redis redis 官方网站:http://www.redi ...
- Python基础 - 系统进程调用
subprocess模块 近期发现还有一个更好的用于取代subprocess的库,sh,也是openstack当中使用的库.
- Unix IPC之Posix消息队列(2)
/* Query status and attributes of message queue MQDES. */ extern int mq_getattr (mqd_t __mqdes, stru ...
- 2017 MoveIt!更新 ros indigo
First MoveIt! Update in 2017. Using it on NEXTAGE pt.1 2017 MoveIt! update pt.2; Stopping motion on ...
- 日志、字段备注查询、自增ID联系设置、常用存储过程
-----获取数据字典SQL(表字段说明)SELECT [Table Name] = OBJECT_NAME(c.object_id), [Column Name] = c.name, ...
- qlserver排序规则在全角与半角处理中的应用
--1.查询区分全角与半角字符--测试数据DECLARE @t TABLE(col varchar(10))INSERT @t SELECT 'aa'UNION ALL SELECT 'Aa'UNIO ...
- BFC 从了解到放弃
最近工作中我突然产生了一个想法,就如我们人类面临的终极问题一般,我从哪里来?我到哪里去?在撸代码进行CSS布局的时候,我会去想,我为什么这么做?,为什么浮动的元素要用overflow?,为什么要用cl ...
- CCF CSP 201503-1 图像旋转
CCF计算机职业资格认证考试题解系列文章为meelo原创,请务必以链接形式注明本文地址 CCF CSP 201503-1 图像旋转 问题描述 旋转是图像处理的基本操作,在这个问题中,你需要将一个图像逆 ...