POJ 3041.Asteroids 最小顶点覆盖
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 22905 | Accepted: 12421 |
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<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<vector>
using namespace std;
#define PI acos(-1.0)
typedef long long ll;
typedef pair<int,int> P;
const int maxn=1e5+,maxm=1e5+,inf=0x3f3f3f3f,mod=1e9+;
const ll INF= 1e13+;
priority_queue<P,vector<P>,greater<P> >q;
vector<int>G[maxn];
int vis[maxn],cy[maxn];
int dfs(int u)
{
for(int i=; i<G[u].size(); i++)
{
int v=G[u][i];
if(vis[v]) continue;
vis[v]=true;
if(cy[v]==-||dfs(cy[v]))
{
cy[v]=u;
return true;
}
}
return false;
}
int solve(int n)
{
int ans=;
memset(cy,-,sizeof(cy));
for(int i=; i<=n; i++)
{
memset(vis,,sizeof(vis));
ans+=dfs(i);
}
return ans;
}
int main()
{
int n,k;
scanf("%d%d",&n,&k);
for(int i=; i<=k; i++)
{
int x,y;
scanf("%d%d",&x,&y);
G[x].push_back(y);
}
cout<<solve(n)<<endl;
return ;
}
二分图最小顶点覆盖
POJ 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 题目大意: 一辆宇宙飞船在一个小行星带中,你知道,这很危险.他有一种武器,可以清除掉一行或一列的小行星.问把小行星全部清除最少的武器使用次 ...
- poj 3041 Asteroids 最小点覆盖/最大匹配
Asteroids Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16242 Accepted: 8833 Descriptio ...
- POJ 3041 Asteroids (最小点覆盖集)
题意 给出一个N*N的矩阵,有些格子上有障碍,要求每次消除一行或者一列的障碍,最少消除多少次可以全部清除障碍. 思路 把关键点取出来:一个障碍至少需要被它的行或者列中的一个消除. 也许是最近在做二分图 ...
- POJ 3041 Asteroids 最小点覆盖 == 二分图的最大匹配
Description Bessie wants to navigate her spaceship through a dangerous asteroid field in the shape o ...
- [poj] 3041 Asteroids || 最小点覆盖=最大二分图匹配
原题 本题为最小点覆盖,而最小点覆盖=最大二分图匹配 //最小点覆盖:用最少的点(左右两边集合的点)让每条边都至少和其中一个点关联. #include<cstdio> #include&l ...
- 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
poj 3041——Asteroids Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22604 Accep ...
随机推荐
- 联想电脑 Wifi开关开不了
"VirtualBox Host-Only Network" 没有有效的IP配置 未修复 自己电脑显示 控制面板>网络和Internet>网络连接 VirtualBo ...
- Trustin Lee
Trustin Lee,MINA.Netty2通讯框架的作者韩国人,80年出生,8岁起在MSX迷你计算机上编写BASIC程序,爱好游戏编程以及使用汇编.C和C++解决编程问题,1998年获得韩国信息奥 ...
- Java String和StringBuffer和StringBuilder
最近在牛课网上做了几道字符串操作的题目,好久没有做题了,之前用的也是大一时C语言做的,对Java字符串操作不太了解,所以深入了解一下String类的相关用法 String构造方法 String() 空 ...
- python 内置函数(一),低阶内置函数功能汇总
python 内置函数 68个 今日主要内容: 1.内置函数 一.内置函数 1.内置函数 详细细节内容地址(id):https://mubu.com/edit/odv-2Dkb6j
- Kubernetes 之上的架构应用
规划并运转一个兼顾可扩展性.可移植性和健壮性的运用是一件很有应战的事情,尤其是当体系杂乱度在不断增长时.运用或体系 本身的架构极大的影响着其运转办法.对环境的依靠性,以及与相关组件的耦合强弱.当运用在 ...
- 在timer的时候突然改变影片简介,先前的不暂停
import flash.display.MovieClip; import flash.utils.Timer; import flash.events.TimerEvent; var hinder ...
- verilog task2
1.问题:串口的发送和接收 系统时钟50Mhz,波特率119200.系统时钟计数约2604个,才是一位数据的传输时间. 模拟接收的任务函数rx_data_task():LSB first task r ...
- TOJ4127: Root of String
传送门:http://acm.tzc.edu.cn/acmhome/problemdetail.do?&method=showdetail&id=4127 4127: Root of ...
- 微信小程序开发——点击按钮获取用户授权没反应或反应很慢的解决方法
异常描述: 点击按钮获取用户手机号码,有的时候会出现点击无反应或很久之后才弹出用户授权获取手机号码的弹窗,这种情况下,也会出现点击穿透的问题(详见:微信小程序开发——连续快速点击按钮调用小程序api返 ...
- nodejs异步读数据库
以下代码不完美,但讲明了使用方法. 回调: function selectUser(callback) { var sql = "SELECT * FROM user"; conn ...