POJ 3041 Asteroids (minimum point coverage)

Source: Internet
Author: User

http://poj.org/problem?id=3041

Asteroids
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 17543 Accepted: 9548

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 (in) and (1,3), and then she could fire down Column 2 to destroy the asteroids at (2,2) and (3,2). minimum point overwrite = maximum match
#include <stdio.h>#include<string.h>#include<math.h>#include<stdlib.h>#defineINF 0x3f3f3f3f#defineN 510intG[n][n], vis[n], used[n];intN;BOOLFind (intu) {    inti;  for(i =1; I <= N; i++)    {        if(!vis[i] &&G[u][i]) {Vis[i]=1; if(!used[i] | |Find (Used[i])) {Used[i]=u; return true; }        }    }    return false;}intMain () {intA, B, K, I, ans;  while(~SCANF ("%d%d", &n, &k)) {ans=0; memset (G,0,sizeof(G));  while(k--) {scanf ("%d%d", &a, &b); G[A][B]=1; } memset (Used,0,sizeof(used));  for(i =1; I <= N; i++) {memset (Vis,0,sizeof(VIS)); if(Find (i)) ans++; } printf ("%d\n", ans); }    return 0;}

POJ 3041 Asteroids (minimum point coverage)

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.