Asteroids----------求二分图的最小顶点覆盖问题
2010-08-21 11:54
399 查看
Asteroids
时间限制(普通/Java):3000MS/10000MS 运行内存限制:65536KByte总提交:34 测试通过:23
描述
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.
输入
* 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.
输出
* Line 1: The integer representing the minimum number of times Bessie must shoot.
样例输入
3 4
1 1
1 3
2 2
3 2
样例输出
2
#include<iostream> #include<vector> using namespace std; int N,K; int a[501][501]; int pre[501]; int x,y; vector< vector<int> >adj; bool deal(int i,bool flag[]) { int j,temp,k; for(j=0;j<adj[i].size();j++) { k=adj[i][j]; if(!flag[k]) { flag[k]=true; temp=pre[k]; pre[k]=i; if(!temp||deal(temp,flag)) { return true; } pre[k]=temp; } } return false; } void hungray() { int i; int sum=0; bool flag[501]={0}; for(i=1;i<=N;i++) { memset(flag,0,sizeof(flag)); if(deal(i,flag)) sum++; } cout<<sum<<endl; } int main() { int i,j; cin>>N>>K; memset(pre,0,sizeof(pre)); adj.assign(N+1,vector<int>()); for(i=1;i<=K;i++) { cin>>x; cin>>y; adj[x].push_back(y); } hungray(); return 0; }
相关文章推荐
- poj3041-Asteroids , 二分图的最小顶点覆盖数 = 最大匹配数
- poj 3041 Asteroids( 最小顶点覆盖,二分图)
- CUGB图论专场2:B - Asteroids 二分图:最小顶点覆盖=最大匹配数
- [poj3041]Asteroids(二分图的最小顶点覆盖)
- pku3308 【论】如何将二分图顶点覆盖问题转化为最小割
- poj 3041 Asteroids(二分图最小顶点覆盖)
- pku3308 【论】如何将二分图顶点覆盖问题转化为最小割
- poj3041-Asteroids , 二分图的最小顶点覆盖数 = 最大匹配数
- POJ3041 Asteroids 二分图最小顶点覆盖 Dinic求解最大流
- POJ 3041-Asteroids(二分图最小顶点覆盖)
- poj3041 - Asteroids (二分图最小顶点覆盖)
- 北大ACM3041——Asteroids~~最小顶点覆盖问题
- poj 2226 二分图 最小顶点覆盖 “草泥马”
- Asteroids POJ3041 二分图最小顶点覆盖
- POJ 3041 Asteroids 二分图最小点覆盖
- POJ - 3041 Asteroids 二分图 最小点覆盖
- POJ1325 Machine Schedule 【二分图最小顶点覆盖】
- poj 3041 Asteroids(二分图 *【矩阵实现】【最小点覆盖==最大匹配数】)
- HDU-1054 Strategic Game(二分图最小顶点覆盖)
- poj3041 Asteroids 最小点覆盖 二分图