BZOJ 1741 [Usaco2005 nov]Asteroids 穿越小行星群 二分图最小边覆盖
来源:互联网 发布:samba windows 编辑:程序博客网 时间:2024/05/07 04:15
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
1 1
1 3
2 2
3 2
INPUT DETAILS:
The following diagram represents the data, where "X" is an
asteroid and "." is empty space:
X.X
.X.
.X.
Sample Output
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).
HINT
#include<bits/stdc++.h>using namespace std;int read(){ int x=0,f=1;char ch=getchar(); while (ch<'0' || ch>'9'){if (ch=='-') f=-1;ch=getchar();} while (ch>='0' && ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f;}const int N=505;int n,K,tag;bool mp[N][N];int vis[N],match[N];bool dfs(int u){int t;for (int i=1;i<=n;i++)if (mp[u][i] && vis[i]!=tag){vis[i]=tag;t=match[i];match[i]=u;if (!t || dfs(t)) return 1;match[i]=t;}return 0;}int main(){n=read(),K=read();for (int i=1;i<=K;i++) mp[read()][read()]=1;tag=0;int ans=0;for (int i=1;i<=n;i++){tag++;if (dfs(i)) ans++;}printf("%d\n",ans);return 0;}
- BZOJ 1741 [Usaco2005 nov]Asteroids 穿越小行星群 二分图最小边覆盖
- BZOJ 1741 [Usaco2005 nov]Asteroids 穿越小行星群 二分图最小覆盖
- bzoj 1741: [Usaco2005 nov]Asteroids 穿越小行星群
- bzoj 1741: [Usaco2005 nov]Asteroids 穿越小行星群 网络流
- bzoj 1741: [Usaco2005 nov]Asteroids 穿越小行星群
- BZOJ 1741: [Usaco2005 nov]Asteroids 穿越小行星群
- BZOJ 1741 [Usaco2005 nov]Asteroids 穿越小行星群题解
- bzoj 1741: [Usaco2005 nov]Asteroids 穿越小行星群 网络流
- [Usaco2005 nov]Asteroids 穿越小行星群
- USACO 2005 Nov Asteroids 小行星群
- poj3041 Asteroids 最小点覆盖 二分图
- POJ3041 Asteroids【二分图最小点覆盖】
- Asteroids POJ3041 二分图最小顶点覆盖
- POJ3041--Asteroids(二分图,最小覆盖点)
- Asteroids----------求二分图的最小顶点覆盖问题
- poj3041 Asteroids 二分图最小点集覆盖
- poj 3041 Asteroids 二分图最小点覆盖
- POJ 3041 Asteroids 二分图 最小点覆盖
- shape画圆角矩形,渐变
- 鼠标 移上 离开 点击 时间
- 线程调度的方法()
- 面试复习-------算法与数据结构------排序
- Python格式化输出
- BZOJ 1741 [Usaco2005 nov]Asteroids 穿越小行星群 二分图最小边覆盖
- 数据库优化
- Okhttp和Retrofit的get,post请求
- viewpager加小圆点及各种问题
- 地下迷宫
- javascript引用传参的坑
- 各种依赖
- 任意变换顺序,a[i]*a[i+1)是4的倍数
- linux下视频格式转换与视频合并