POJ 3020 Antenna Placement (Minimum path overlay + composition)

Source: Internet
Author: User

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

Antenna Placement

Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 7565 Accepted: 3758

Description

The Global aerial Centre have been allotted the task of building the fifth generation of mobile phone nets in swed En. 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

The first row of input is a single positive an integer n, 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 matrix, on a row of its own.

Sample Input

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

Sample Output

175

For details, please refer to:

http://blog.csdn.net/ripwangh/article/details/47334941

Main topic:

Given a map, * representing the city, O representing the open space, using an antenna to cover two adjacent cities, how many antennas does the minimum need to ask? (the so-called adjacent refers to the upper and lower left and right 4 directions adjacent)

Minimum path coverage problem, the difficulty is how to compose

If this is the case:

2
3 3
*oo
***
O*o

Count the number of cities and number them:

2
3 3
1oo
234
o5o

The first city number 1, the antenna can cover the city adjacent to it 2, then 1 and 2 there is a connection between 1 and 2 that is g[1][2]= 1;

The second City number 2, the antenna can cover the city adjacent to it 1,3; g[2][1]=1,g[2][3]=1;

The same can be g[3][2]=1,g[3][4]=1,g[3][5]=1,g[4][3]=1,g[5][3]=1.

Split the city into two parts, respectively, into set X and set Y

X Y

1 1

2 2

3 3

4 4

5 5

After the composition:

X 1 2 3 4 5
Y
1 0 1 0 0 0
2 1 0 1 0 0
3 0 1 0 1 1
4 0 0 1 0 0
5 0 0 1 0 0


Minimum path override = Total number of points-maximum matches

Because the city is split into two parts, the maximum match to be obtained should be divided by 2.

#include <stdio.h>#include<queue>#include<string.h>#include<algorithm>#defineINF 0x3f3f3f3f#defineN 1010using namespacestd;intG[n][n], a[n][n], vis[n], used[n];CharMaps[n][n];intM, N, K, d[4][2] = {{0,1}, {0, -1}, {1,0}, {-1,0}};BOOLFind (intU//find the maximum match{    inti;  for(i =1; I <= K; i++)    {        if(!vis[i] &&G[u][i]) {Vis[i]=1; if(!used[i] | |Find (Used[i])) {Used[i]=u; return true; }        }    }    return false;}voidBuild (intXintY//composition{    intA, B, I;  for(i =0; I <4; i++)//Wireless will cover four directions{a= x + d[i][0]; b= y + d[i][1]; if(A >=1&& a <= m && b >=1&& b <=N) {g[a[x][y]][a[a][b]]=1; G[a[a][b]][a[x][y]]=1; }    }}intMain () {intT, I, J; scanf ("%d", &t);  while(t--) {scanf ("%d%d", &m, &N); memset (G,0,sizeof(G)); memset (A,0,sizeof(A)); K=1;  for(i =1; I <= m; i++) {GetChar ();  for(j =1; J <= N; J + +) {scanf ("%c", &Maps[i][j]); if(Maps[i][j] = ='*') {A[i][j]= k;//A[i][j] Represents the number of the city with coordinates of (I,J)k++; }            }        }//count the number of cities and number themK-=1;  for(i =1; I <= m; i++)        {             for(j =1; J <= N; J + +)            {                if(A[i][j])//every city that is found is based on the composition of its surroundings .Build (i, j); }        }        intAns =0; memset (Used,0,sizeof(used));  for(i =1; I <= K; i++) {memset (Vis,0,sizeof(VIS)); if(Find (i)) ans++; } printf ("%d\n", K-ans/2); }    return 0;}/*3*oo***o*o*/
View Code

POJ 3020 Antenna Placement (Minimum path overlay + composition)

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.