POJ 3041--asteroids "binary map && minimum number of points overlay"

Source: Internet
Author: User

Asteroids
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 17861 Accepted: 9729

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

Test instructions

There's a n-n grid in space, a grid of K dangerous asteroids, a weapon that requires only one bullet to destroy all the asteroids in a row or column. Ask at least how many bullets are needed to destroy all the asteroids.


Ideas:

Bare minimum point coverage number topic. Water and water.

 #include <cstdio> #include <cstring> #include <algorithm> #define MAXN 550using namespace Std;int map[maxn][maxn];int used[maxn];int link[maxn];int N, m;void init () {memset (map, 0, sizeof (MA p));}        void Getmap () {while (m--) {int A, B;        scanf ("%d%d", &a, &b);    MAP[A][B] = 1;            }}bool dfs (int x) {for (int i = 1; I <= n; ++i) {if (Map[x][i] &&!used[i]) {used[i] = 1;                if (link[i] = = 1 | | DFS (LINK[I])) {link[i] = x;            return true; }}} return false;}    int Hungary () {int ans = 0;    memset (link, 1, sizeof);        for (int i = 1; I <= n; ++i) {memset (used, 0, sizeof (used));    if (Dfs (i)) ans++; } return ans;        int main () {while (scanf ("%d%d", &n, &m)! = EOF) {init ();        Getmap ();        int sum = Hungary ();    printf ("%d\n", sum); } return 0;} 


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

POJ 3041--asteroids "binary map && minimum number of points overlay"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.