http://poj.org/problem?id=3041
Asteroids
Time Limit: 1000MS |
|
Memory Limit: 65536K |
Total Submissions: 14476 |
|
Accepted: 7880 |
Description
Bessie wants to navigate she spaceship through a dangerous asteroid field in the shape of an n x N grid (1 <= N <= 5 ). The grid contains K asteroids (1 <= k <=), which is conveniently located at the lattice points of the G Rid.
Fortunately, Bessie have a powerful weapon that can vaporize all the asteroids on any given row or column of the grid with A single shot. This weapon was quite expensive, so she wishes to use it sparingly. Given the location of the asteroids in the field, find the minimum number of shots Bessie needs to fire to eliminate a ll of the asteroids.
Input
* Line 1:two integers N and K, separated to a single space.
* Lines 2..k+1:each line contains, 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 41 11 32 23 2
Sample Output
2
Hint
INPUT DETAILS:
The following diagram represents the data, where "X" is a asteroid and "." is empty space:
x.x
. X.
. X.
The main idea is that the missile can eliminate the obstacles on the line, give the position of the obstacle, ask at least how many missiles are needed, and put one side of the line in the matrix. Column release vessel has one side, according to the two-part diagram do, it is not very difficult, this kind of topic is mainly the main function there is a little different, other sets of templates.
Template questions
AC Code:
#include <stdio.h> #include <string.h> #define MAXN 510int n,k,ans;bool map[maxn][maxn];int MATCH[MAXN]; BOOL Vis[maxn];bool Find (int u) {int i;for (i=1; i<=n; i++) {if (Map[u][i] &&!vis[i]) {Vis[i] = true;if (match [I] = =-1 | | Find (Match[i])) {Match[i] = U;return true;}}} return false;} int main () {int i,x,y;ans = 0;scanf ("%d%d", &n,&k); memset (map,0,sizeof (map)); Memset (match,-1,sizeof (match)); for (i=0; i<k; i++) {scanf ("%d%d", &x,&y); map[x][y] = 1;} for (I=1; i<=n; i++) {memset (vis,0,sizeof (VIS)); if (find (i)) ans++;} printf ("%d\n", ans); return 0;}
POJ 3041 (maximum matching problem)