Asteroids(二分图最大匹配模板题)
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 12323 | Accepted: 6716 |
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).
#include<stdio.h>
#include<string.h>
int map[][];
int link[];
int vis[];
int n;
bool dfs(int u)
{
int v;
for(v = ; v <= n; v++)
{
if(map[u][v] && !vis[v])
{
vis[v] = ;
if(link[v] == - || dfs(link[v]))
{
link[v] = u;
return true;
}
}
}
return false;
}
int main()
{ int k,u,v,res;
memset(map,,sizeof(map));
scanf("%d %d",&n,&k);
while(k--)
{
scanf("%d %d",&u,&v);
map[u][v] = ;
}
memset(link,-,sizeof(link));
res = ;
for(u = ; u <= n; u++)
{
memset(vis,,sizeof(vis));
if(dfs(u)) res++;
}
printf("%d\n",res);
return ; }
Asteroids(二分图最大匹配模板题)的更多相关文章
- 【HDU 2063】过山车(二分图最大匹配模板题)
题面 RPG girls今天和大家一起去游乐场玩,终于可以坐上梦寐以求的过山车了.可是,过山车的每一排只有两个座位,而且还有条不成文的规矩,就是每个女生必须找个个男生做partner和她同坐.但是,每 ...
- HDU - 1054 Strategic Game (二分图匹配模板题)
二分图匹配模板题 #include <bits/stdc++.h> #define FOPI freopen("in.txt", "r", stdi ...
- 二分图最大匹配模板【匈牙利;Dinic最大流】
二分图最大匹配模板[匈牙利:Dinic最大流] 匈牙利算法 int n,m; vector<int> map[100010]; int match[100010];//保存匹配的互相点 b ...
- POJ 3041 Asteroids(二分图模板题)
Bessie wants to navigate her spaceship through a dangerous asteroid field in the shape of an N x N g ...
- hdu1083二分图匹配模板题
onsider a group of N students and P courses. Each student visits zero, one or more than one courses. ...
- poj 3041 Asteroids (二分图的最大匹配 第一题)
题目:http://poj.org/problem?id=3041 题意:在某个n*n的空间内,分布有一些小行星,某人在里面打炮,放一枪后某一行或某一列的行星就都没了,让求最少的打炮数. 然后把每行x ...
- PKU 3041 Asteroids 最小点覆盖(最大匹配模板题)
题目大意:给你一个N*N的矩阵, 里面有K个星球, 我们可以让武器攻击矩阵的一行或者一列来使得这个星球被击碎, 现在问你最少需要几个这种武器才能把所有的星球击碎? 解题思路:关键是建模构图 把每一行当 ...
- HDU-2063(二分图匹配模板题)
过山车Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submissi ...
- POJ 3041 Asteroids 二分图
原题连接:http://poj.org/problem?id=3041 Asteroids Time Limit: 1000MS Memory Limit: 65536K Total Submis ...
随机推荐
- 用Wget进行下载
wget下载可以不用考虑资源的双向认证的问题,即 wget -N -S -O " + filePath + " " + urlStr + " --no-chec ...
- 新闻web小酌
首页如上 类图如下: 添加新闻的方法(dao): public boolean Add(News news) { boolean flag=false; Connection con =getConn ...
- 移动页面缩放方法之(三)rem布局
<!DOCTYPE HTML> <html lang="zh-cn"> <head> <meta http-equiv="Con ...
- 5事件DOM零级事件跟DOM二级事件
事件的行为传播,行为本身跟事件绑定没有关系:1.全新认识事件(某一个具体的行为)->行为本身:浏览器天生自带的一些行为操作->click,mouseover(mouseenter),mou ...
- 一个类实现多个接口的demo
//A接口 interface A{ public int getA(); } //B接口 interface B{ public int getB(); } //实现了某个接口必须实现其全部的方法 ...
- C# - 二叉树表达式计算
很早以前就写过双栈的表达式计算. 这次因为想深入学一下二叉树,网上都是些老掉牙的关于二叉树的基本操作. 感觉如果就学那些概念,没意思也不好记忆.于是动手写了一个表达式计算的应用例子. 这样学习印象才深 ...
- Ext.grid.Panel表格分页
转载:http://www.cnblogs.com/libingql/archive/2012/04/22/2464994.html cshtml @{ Layout = null; } <!D ...
- Android 自定义日历
好久没来写博客了,这半年多发生了好多的事情,废话不多说,今天在公司里比较闲在,写一篇最近写的公司用到的控件——日历控件. 控件的功能比较少,根据需求只有选择开始时间和结束时间并返回时间段. 效果图如下 ...
- Java方法的参数是按值传递的.【转】
在Java中,所有的方法参数,都是"按值传递". 有那么一种说法,Java中基本类型是按值传递,对象是按引用传递.这个说法其实是不确切的,确切的说法是 Java中基本类型将值作为参 ...
- 安卓应用开发用户体验之禁止EditText自动获取焦点
一.问题描述: 在安卓应用开发时,经常会在同一个页面有许多不同的控件,在用户操作时,如何正确的在这些控件之间来回切换是良好用户体验的重要问题.可能会碰到如下问题:在点击页面内某控件时(假设控件为Spi ...