Asteroids
Time Limit: 1000MS |
|
Memory Limit: 65536K |
Total Submissions: 16211 |
|
Accepted: 8819 |
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.
OUTPUT DETAILS:
Bessie may fire across row 1 to destroy the asteroids at (all) and (1,3), and then she could fire down column 2 to destroy T He asteroids at (2,2) and (3,2).
Source
Usaco 2005 November Gold
1#include <stdio.h>2#include <string.h>3 Const intM =510 ;4 BOOLMap[m][m];5 intGirl[m];6 BOOLSta[m];7 intN, M;8 9 BOOLHungary (intx)Ten { One for(inti =1; I <= N; i++) { A if(Map[x][i] && sta[i] = =false) { -Sta[i] =true ; - if(Girl[i] = =0||Hungary (Girl[i])) { theGirl[i] =x; - return true ; - } - } + } - return false ; + } A at intMain () - { - //freopen ("A.txt", "R", stdin); - while(~ scanf ("%d%d", &n, &m)) { - intX, y, k =0 ; -memset (Map,0,sizeof(map)); inMemset (Girl,0,sizeof(Girl)); - for(inti =0; I < m; i++) { toscanf ("%d%d", &x, &y); +Map[x][y] =1 ; - } the intall =0 ; * for(inti =1; I <= N; i++) { $memset (STA,0,sizeof(STA));Panax Notoginseng if(Hungary (i)) -all++ ; the } +printf ("%d\n", all); A } the return 0 ; +}
View Code
Minimum coverage point = maximum number of matches. (Hungary is to ask for the maximum number of matches)
Asteroids (Hungarian algorithm)