# poj 3041 Asteroids 题解

Asteroids

 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20686 Accepted: 11239

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).

Source

[Submit]   [Go Back]   [Status]   [Discuss]

——————————————————-——————————我是分割线——————————————————————————————————————

最小点覆盖数 = 最大匹配数

``` 1 /*
2     Problem:
3     OJ:
4     User:
5     Time:
6     Memory:
7     Length:
8 */
9 #include<iostream>
10 #include<cstdio>
11 #include<cstring>
12 #include<cmath>
13 #include<algorithm>
14 #include<queue>
15 #include<cstdlib>
16 #include<iomanip>
17 #include<cassert>
18 #include<climits>
19 #include<vector>
20 #include<list>
21 #include<map>
22 #define maxn 501
23 #define F(i,j,k) for(int i=j;i<=k;i++)
24 #define M(a,b) memset(a,b,sizeof(a))
25 #define FF(i,j,k) for(int i=j;i>=k;i--)
26 #define inf 0x7fffffff
27 #define maxm 2016
28 #define mod 1000000007
29 //#define LOCAL
30 using namespace std;
32     int x=0,f=1;char ch=getchar();
33     while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}
34     while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();}
35     return x*f;
36 }
37 int n,m,k;
38 int g[maxn][maxn];
39 int px[maxn],py[maxn];
40 bool vis[maxn];
41 inline int path(int u)
42 {
43     F(i,1,n){
44         if(g[u][i]&&!vis[i])
45         {
46             vis[i]=true;
47             if(py[i]==-1||path(py[i]))
48             {
49                 px[u]=i;
50                 py[i]=u;
51                 return 1;
52             }
53         }
54     }
55     return 0;
56 }
57 inline int solve()
58 {
59     int cnt=0;
60     M(px,-1);M(py,-1);
61     F(i,1,n){
62         if(px[i]==-1){
63             M(vis,false);
64             cnt+=path(i);
65         }
66     }
67     return cnt;
68 }
69 int main()
70 {
71     std::ios::sync_with_stdio(false);//cout<<setiosflags(ios::fixed)<<setprecision(1)<<y;
72     #ifdef LOCAL
73     freopen("data.in","r",stdin);
74     freopen("data.out","w",stdout);
75     #endif
76     cin>>n>>k;
77     F(i,1,k){
78         int x,y;
79         cin>>x>>y;
80         g[x][y]=1;
81     }
82     cout<<solve()<<endl;
83     return 0;
84 }```

## POJ 3041 Asteroids (匈牙利算法)

Asteroids Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 14388 Accepted: 7828 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 astero

## poj 3041——Asteroids

poj       3041——Asteroids Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22604   Accepted: 12247 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 g

## POJ 3041 Asteroids （图论-最小点覆盖）

Asteroids Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 15079   Accepted: 8240 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 as

## poj 3041 Asteroids(最小点覆盖)

http://poj.org/problem?id=3041 Asteroids Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 17543   Accepted: 9548 Description Bessie wants to navigate her spaceship through a dangerous asteroid field in the shape of an N x N grid (1 <= N <

## POJ 3041.Asteroids 最小顶点覆盖

Asteroids Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22905   Accepted: 12421 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 a