POJ 3020--Minimum path coverage

Source: Internet
Author: User
Tags first row
H-antenna Placement Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%lld &%llu Submit Status Practice POJ 3020

Description The Global aerial Centre has been allotted the task of building the fifth generation of mobile phone Nets in Sweden. The most striking reason so they got the job, is their discovery of a new, highly noise resistant, antenna. It's called 4DAir, and comes in four types. Each type can is transmit and receive signals in a direction aligned with a (slightly skewed) latitudinal and Longitudin Al 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 a example picture of places of interest, depicted by twelve small rings, and nine 4DAir antennas depicted by ell Ipses covering them.

Obviously, it is desirable to use as few antennas as possible, but still provide coverages for each place of interest. We model The problem as follows:let A is a rectangular matrix describing the surface of Sweden, where an entry of a eithe R is a point of interest, which must are covered by at least one antenna, or empty space. Antennas can only is positioned at the entry in A. When an antenna was placed at row R and column C, this entry was considered covered, but also one of the neighbouring Entrie S (c+1,r), (c,r+1), (C-1,r), or (C,R-1), is covered depending on the type chosen for this particular antenna. What's the least number of antennas for which there exists a placement in a such so all points of interest are covered?

Input on the first row of input was a single positive integer n and specifying the number of scenarios that follow. Each scenario begins with a row containing the positive integers h and W, with 1 <= h <= 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 CH Aracters 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 Matri x, on a row of its own.

Sample Input

2
7 9
ooo**oooo
**oo*ooo*
o*oo**o**
ooooooooo
*******oo
o*o*oo*oo
*******oo
1 * * *
o
*
* * * * * *

Sample Output

17

5

Test instructions: In a n*m board, * denotes the city, O represents the open space, to install all the cities on the antenna, each antenna can cover the adjacent two cities

Ask at least how many antennas to build

It is obvious that the minimum path is covered, and each path is two points (obviously a two-point chart), and the minimum number of paths can cover all points, marking each city, neighboring cities

Build edge, build bidirectional edge, find maximum match, minimum path overwrite = number of nodes-maximum number of matches

#include <iostream> #include <string.h> using namespace std;
int g[405][405],nmp[200][200];
Char mp[200][200];
int dx[5]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int un,vn;
int linker[500],used[500]; bool Dfs (int u) {for (int v=1;v<=vn;v++) {if (G[u][v]&&!used[v]) {used[v]=
            True if (linker[v]==-1| |
                DFS (Linker[v])) {linker[v]=u;
            return true;
}}} return false;
    } int solve () {int res=0;
    memset (LINKER,-1,SIZEOF (linker));
        for (int u=1;u<=un;u++) {memset (used,false,sizeof (used));
    if (DFS (U)) res++;
} return res;
    } int main () {int t;
    int n,m;
    cin>>t;
        while (t--) {cin>>n>>m;
        int tot=1;
        Memset (Mp,0,sizeof (MP));
        memset (nmp,0,sizeof (NMP));
    for (int i=1;i<=n;i++) {for (int j=1;j<=m;j++) {            cin>>mp[i][j];
                if (mp[i][j]== ' * ') {nmp[i][j]=tot++;
        }}} memset (G,0,sizeof (g));
                for (int i=1;i<=n;i++) {for (int j=1;j<=m;j++) {if (mp[i][j]== ' * ')
                    for (int k=0;k<4;k++) {int nx=dx[k]+i;
                    int ny=dy[k]+j;
                if (mp[nx][ny]== ' * ') g[nmp[i][j]][nmp[nx][ny]]=1;
        }}} un=tot-1;
        vn=tot-1;
        int Ans=solve ();
        cout<<ans<<endl;

    cout<<tot-1-ans/2<<endl;
} 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.