Poj3020antenna Placement (Minimum path overlay + weight in composition)

Source: Internet
Author: User

Antenna Placement
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 7788 Accepted: 3880

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

http://blog.csdn.net/lyy289065406/article/details/6647040

Main topic:

A rectangle, there are n cities ' * ', now the N cities have to cover the wireless, if you place a base station, then it can cover up to two adjacent cities.
Q. How many base stations can be placed at least to make all the cities covered by wireless?


Problem Solving Ideas:

After thinking, vaguely can be thought of as a two-dimensional map of the minimum path coverage problem (I would like to ask for some coverage, but if you think of a separate point, it will exclude point coverage, because the dot is covered by the connection)

(Note that it is not a minimum dot overlay)

So the next thing to be sure is,

Whether it is to seek the minimum path coverage of a binary graph or to find the least way coverage of a non-binary graph

Because the direction and the non-direction are different calculation methods.

To determine whether to construct a map, or to construct an test instructions graph, it is necessary to look at the way in which the binary diagram is constructed, and more appropriate to construct a binary graph.

And then went into the difficult point: How to construct a binary map

First of all, the input of a bunch of "circle stars" can be seen as a large map, the map has all the coordinates of the city, but there is a misunderstanding: the city can not simply two x, y coordinates as a prepared to construct the two vertex set of the binary map.

The city is the vertex of the two-part plan to be constructed!

The construction method is as follows:

For example, enter:

*oo

***

O*o

, it can be abstracted as a digital map:

100

234

050

The number is based on the city order entered as the city's number, 0 means there is no city in that location.

Then, according to the "scope" rule of the topic, starting from the first city, and using itself as the central city, connect to the cities in four directions (covering)

So you can get the edge set:

E12 E21 E32 e43 E53

E23 E34

E35

As you can see, these edges have a forward edge, but each edge has a corresponding opposite edge.

That is, the edges between any two cities (vertices) are paired up.

Then we can be sure that we should construct the non-directional binary graph (in fact, no direction = bidirectional)

Because if you want to construct an axially-divided graph, you need to judge the edges that have appeared, which is a cumbersome task.

In order to construct the graph G as a non-direction graph, it is necessary to introduce a "split" of the term.

In fact, the original to each vertex of the graph G "Split (I think copy more accurate)" As 2 points, respectively, belong to the structure of the two sub-graph of the two vertex set

For example, in the example that was just taken, an example of an e12 is drawn:

Copy vertex 1 and Vertex 2, make 1,2∈v1 1 ', 2 ' ∈v2, not hard to find | v1|=| v2|

According to the side E12 and E21, get the graph of the non-direction two:


So in the same vein you can get the example of the non-binary graph:


Then, through the V1 binary graph, the elements of the row,v2 as the elements of Col, to construct the matrix stored to the computer

1 ' 2 ' 3 ' 4 ' 5 '

1 F T F f f

2 T F t f F

3 f t f t t

4 F F T f F

5 F F T f F

The next step is to ask for the smallest path of the non-binary graph to cover

Using the formula:

Minimum path overlay for a non-binary graph = number of vertices – maximum binary match/2

Top points: Is the number of cities used to construct the non-binary graph, that is, the number of vertices before the "split" operation

The maximum binary matching book is divided by 2 because the "split" is done so that the total number of matches is one-fold, so divide by 2 to get the true match number of the original.

The last remaining problem is to find the maximum number of binary matching, with the Hungarian algorithm, which is not much to say, refer to the practice of POJ3041, basically a touch.


A conclusion is drawn from this question:

When the two vertex subset cardinality of a binary is equal, the matching number of all vertices of the binary graph is equal to twice times the number of matches of any one vertex subset.

In fact, the Hungarian algorithm problem solving is extremely simple, but the difficulty of graph theory is not difficult to answer, but the process of building a map , it is no wonder there will be cows Yue: With the Hungarian algorithm, the building is painful, and finally happy.

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5 using namespacestd;6 Const intMAX = -;7 intg[max][max],s[max*max][max*MAX];8 intvis[ -],link[ -];9 Charch;Ten intt,m,n,k; One intDfsintx) A { -      for(inti =1; I < K; i++) -     { the         if(Vis[i] = =0&&S[x][i]) -         { -Vis[i] =1; -             if(Link[i] = =0||DFS (Link[i])) +             { -Link[i] =x; +                 return true; A             } at         } -     } -     return false; - } - intMain () - { inscanf"%d",&t); -      while(t--) to     { +K =1; -scanf"%d%d",&n,&m); theMemset (G,0,sizeof(g)); *memset (s),0,sizeof(s)); $memset (Link,0,sizeof(link));Panax Notoginseng GetChar (); -          for(inti =1; I <= N; i++) the         { +              for(intj =1; J <= M; J + +) A             { thescanf"%c",&ch); +                 if(ch = ='*') -G[I][J] = k++; $             } $ GetChar (); -         } -          for(inti =1; I <= N; i++) the         { -              for(intj =1; J <= M; J + +)Wuyi             { the                 if(G[i][j]) -                 { Wu                     if(G[i-1][j]) -s[G[i][j] [g[i-1][J]] =1; About                     if(G[i +1][j]) $s[G[i][j] [g[i +1][J]] =1; -                     if(G[i][j +1]) -s[G[i][j] [g[i][j +1] ] =1; -                     if(G[i][j-1]) As[G[i][j] [g[i][j-1] ] =1; +                 } the  -             } $         } the         intAns =0; the          for(inti =1; I < K; i++) the         { thememset (Vis,0,sizeof(Vis)); -             if(Dfs (i)) inans++; the         } theprintf"%d\n", K-ans/2-1); About     } the  the     return 0; the}
View Code

Poj3020antenna Placement (Minimum path overlay + weight in 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.