Poj 3020 antenna placement

Source: Internet
Author: User

This question is to find at least how many launch devices need to be built, and the obvious binary match. However, the undirected graph is created, so it will be doubled in coverage, in fact, some points are repeated, so we need to output the total number-half of the matching points of the record ,,

Antenna placement
Time limit:1000 ms   Memory limit:65536 K
Total submissions:5576   Accepted:2793

Description

The global aerial research centre has been allotted the task of building the maximum th generation of mobile phone nets in Sweden. the most striking reason why they got the job, is their discovery of a new, highly noise resistant, antenna. it is called 4 dair, and
Comes in four types. each type can only transmit and receive signals in a direction aligned with a (slightly skewed) latitudinal and longitudinal grid, because of the interacting electromagnetic field of the Earth. the four types correspond to antennas operating
In the directions north, west, south, and East, respectively. below is an example picture of places of interest, depicted by twelve small rings, and nine 4 Dair antennas depicted by ellipses covering them.
 
Obviusly, it is desirable to use as few antennas as possible, but still provide coverage for each place of interest. we model the problem as follows: Let A be a rectangular matrix describing the surface of Sweden, where an entry of a either is a point of interest,
Which must be covered by at least one antenna, or empty space. antennas can only be positioned at an entry in. when an antenna is placed at row R and column C, this entry is considered covered, but also one of the neighbouring entries (C + 1, R), (C, R + 1), (C-1, R ),
Or (C, R-1), is covered depending on the type chosen for this particle antenna. what is the least number of antennas for which there exists a placement in a such that all points of interest are covered?

Input

On the first row of input is a single positive integer N, specifying the number of scenarios that follow. each scenario begins with a row containing two positive integers H and W, with 1 <= H <= 40 and 0 <W <= 10. thereafter is a matrix presented, describing
The points of interest in Sweden in the form of H lines, each containing W characters from the set ['*', 'O']. A '*'-character symbolises a point of interest, whereas a 'O'-character represents open space.

Output

For each scenario, output the minimum number of antennas necessary to cover all '*'-entries in the scenario's matrix, on a row of its own.

Sample Input

27 9ooo**oooo**oo*ooo*o*oo**o**ooooooooo*******ooo*o*oo*oo*******oo10 1***o******

Sample output

175
#include <stdio.h>#include <string.h>#include <iostream>using namespace std;int sum, link[500], k;int map[500][500], v[500], dp[500][500];int dfs(int x){    for(int y = 1; y <= k; y++)    {        if(map[x][y] && !v[y])        {            v[y] = 1;            if(link[y] == 0 || dfs(link[y]))            {                link[y] = x;                return 1;            }        }    }    return 0;}void hungray(){    for(int i = 1; i <= k; i++)    {        memset(v , 0 , sizeof(v));        if(dfs(i))        sum++;    }}int main(){    char s[50][50];    int t, n, m, i, j;    scanf("%d",&t);    while(t--)    {        k = 0;        memset(map , 0 , sizeof(map));        memset(dp , -1 , sizeof(dp));        memset(link , 0 , sizeof(link));        scanf("%d %d",&n, &m);        for(i = 1; i <= n; i++)            scanf("%s",s[i]);        for(i = 1; i <= n; i++)            for(j = 0; j < m; j++)            {                if(s[i][j] == 'o')                    dp[i][j+1] = 0;                else if(s[i][j] == '*')                    dp[i][j+1] = ++k;            }        for(i = 1; i <= n; i++)        {            for(j = 1; j <= m; j++)            {                if(dp[i][j] > 0)                {                    if(dp[i-1][j] > 0)                        map[dp[i][j]][dp[i-1][j]] = 1;                    if(dp[i+1][j] > 0)                        map[dp[i][j]][dp[i+1][j]] = 1;                    if(dp[i][j-1] > 0)                        map[dp[i][j]][dp[i][j-1]] = 1;                    if(dp[i][j+1] > 0)                        map[dp[i][j]][dp[i][j+1]] = 1;                }            }        }        sum = 0;        hungray();        printf("%d\n",k-sum/2);    }    return 0;}

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.