Placement POJ3020-Antenna

Source: Internet
Author: User

 

Reprinted please indicate the source: Thank you

Http://user.qzone.qq.com/289065406/blog/1299322779

Tip: do not be misled by the circle of pictures. You can see clearly that '*' is a city, 'O' is an open space, and the antenna of an elliptical circle must cover the city '*', instead of covering the Open Space

 

Question:

In a rectangle, there are n Cities '*'. Now all N cities need to cover wireless networks. If a base station is placed, it can cover at most two adjacent cities.
How many base stations can be placed to ensure that all cities are wireless?

Solution:

After thinking, It can be thought of as a resultMinimum path overwrite of a Bipartite GraphProblem

(Note that it is not the minimum coverage)

 

So what needs to be confirmed next is,

Is the minimum path coverage of a directed bipartite graph or the minimum path coverage of a directed bipartite graph?

This is because the normal direction and undirected direction are completely different calculation methods.

 

To determine whether to construct a directed graph or an undirected graph, you must first look at the method used to construct a Bipartite Graph Based on the question. This is more suitable for constructing a bipartite graph.

 

Then enterDifficulty: how to construct a Bipartite Graph

 

The first thing to be clear is that the input pile of "circled Stars" can be regarded as a big map with the coordinates of all cities, but there is a misunderstanding: we cannot simply take the two X and Y coordinates of the city as the two vertex sets of the Binary Graph to be constructed.

The city is the vertex of the Bipartite Graph to be constructed!

The constructor is as follows:

For example, enter:

* Oo

***

O * o

Can be abstracted as a digital map:

100

234

050

The number is the number of the city according to the entered city order. 0 indicates that there is no city in the location.

Then, based on the "Scope" rule of the question, connect the first city to the four cities (covering) with itself as the central city)

Therefore, the edge set can be obtained:

E12 E21 E32 E43 e53

E23 e34

E35

We can see that all these edges have directed edges, but each edge has an opposite edge.

That isThe edges between any two cities (vertices) are paired.

Then we can determine, we shouldConstruct a undirected bipartite graph (in fact, undirected = bidirectional)

This is because it is very troublesome to determine the existing edge when constructing a directed bipartite graph.

 

To construct a directed graph G as a undirected bipartite graph, we need to introduce a new term "split point"

In fact, each vertex of the original directed graph G is split (I think the replication is more accurate) into two vertices, which belong to the two vertex sets of the Bipartite Graph to be constructed respectively.

 

For example, in the previous example, extract a directed edge E12 for example:

Copy vertex 1 and vertex 2 so that 1, 2, and V1; 1', 2, and v2 are not difficult to find. | V1 | = | V2 |

Based on the edges E12 and E21, the undirected bipartite graph is obtained:

 

In the same way, we can see that the undirected bipartite graph of the preceding example is:

 

Then, using the undirected bipartite graph, the V1 element as the row and V2 element as the Col, the reachable matrix is constructed and stored in the computer.

1 '2' 3 '4' 5'

1 f t f

2 t f

3 f t

4 f t f

5 f t f

 

Next, we need to overwrite the minimum path of this undirected bipartite graph.

Formula:

 

Least path overwrite of undirected bipartite graph = number of vertices-Maximum number of bipartite matching/2

 

Number of vertices: the number of cities used to construct a undirected bipartite graph, that is, the number of vertices before the "split point" operation.

The maximum binary matching book is divided by 2 because the "split point" Operation doubles the total number of matches. Therefore, the true matching number of the source image is obtained by dividing 2.

 

The remaining problem is to find the maximum binary matching number. Using the Hungary algorithm, this is not much to mention. Refer to the practices of poj3041, which is basically the same.

 

The following is a conclusion:

When the base number of two vertex subsets in a bipartite graph is equal, the matching number of all vertices in the bipartite graph is equal to twice the matching number of any vertex subset.

In fact, the Hungarian algorithm is extremely simple to solve,Graph Theory is not difficult to answer, but the process of creating a graph.It is no wonder that there will be Niu Yue: using the Hungary algorithm, creating images is painful, and finally happy.

 

 

// Memory time // 420 K 16 Ms # include <iostream> using namespace STD; int ipmap [41] [11]; // mark the location of the city, the city id int IP address is recorded in sequence; // city number (eventually the number of cities) int V1, V2; // two vertex sets int m in the bipartite graph; // The maximum binary match bool City [401] [401]; // indicates whether two cities can be connected. // split each city into two cities through the "split point" operation, belongs to the two points set bool vist [401]; int link [401]; int dire_r [4] = }; int dire_c [4] = {,-}; // corresponds to the top, bottom, left, right, and * Hungary algorithm */bool DFS (int x) {for (INT y = 1; y <= V2; y ++) If (City [x] [Y] &! Vist [y]) {vist [y] = true; If (link [y] = 0 | DFS (link [y]) {link [y] = X; return true ;}} return false;} void search (void) {for (INT x = 1; x <= V1; X ++) {memset (vist, false, sizeof (vist); If (DFS (x) m ++;} return;} int main (void) {int test, H, W; CIN> test; while (test --) {/* Initial */memset (ipmap, 0, sizeof (ipmap); memset (city, false, sizeof (city); memset (link, 0, sizeof (Link); IP = 0; M = 0;/* read in the maps */CIN> H> W; int I, j; char temp; for (I = 1; I <= H; I ++) for (j = 1; j <= W; j ++) {CIN> temp; if (temp = '*') ipmap [I] [J] = ++ IP;}/* structure the bipartite graphs */for (I = 1; I <= H; I ++) for (j = 1; j <= W; j ++) if (ipmap [I] [J]) for (int K = 0; k <4; k ++) {int x = I + dire_r [k]; int y = J + dire_c [k]; if (ipmap [x] [Y]) City [ipmap [I] [J] [ipmap [x] [Y] = true; // The "split point" operation is "by the way".} // after the construction of the Bipartite Graph is completed, the problem that follows will be handled in the same way as that of poj3041. V1 = v2 = IP; /* augmented track search */search ();/* output */cout <IP-M/2 <Endl; // undirected bipartite graph: minimum path overwrite = number of vertices in the source image before "split"-Maximum number of matching/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.