Poj 3020 antenna placement solution report

Source: Internet
Author: User

Question link: http://poj.org/problem? Id = 3020

First of all, ignore the one that may mislead others (maybe I have poor understanding, or I am misled by a little bit ).

An H * w graph is provided. "*" indicates point of interest, and "O" ignores it. You can draw a circle on "*" (assuming that the coordinate of this "*" is (I, j, each circle can only enclose a point around it (or above (I-1, j) or below (I + 1, J) or left (I, J-1) or (I, j + 1), that is, this circle can only cover two "*" points. Ask the minimum number of such circles to include the "*" of the domicile "*".

This is essentially the minimum number of path overwrites for a undirected bipartite graph. The most important thing is creating a graph !!!!

You also need to know a formula:Least path overwrite of undirected bipartite graph = number of vertices-Maximum number of bipartite matching/2

It's so powerful to refer to other people's graph creation methods ~~~~

The figure is shown as follows: every time a "*" is encountered, the number of this "*" is recorded, just like the second line of the Figure 7 9, its "*" is sequentially numbered 3 4 5 6, because the "*" in the first line has used numbers 1 and 2, essentially, this "*" is the number of points of interest. Next, traverse each "*" (assuming the number is I) in four directions. If a direction also has "*" (number is J ), then I and j are connected.

Finally, the Hungary template calculates the number of matches. As for the total number, it is the number of vertices in the formula. When the formula is nested, the result is also success ........

1 # include <iostream> 2 # include <cstdio> 3 # include <cstring> 4 using namespace STD; 5 6 const int maxn = 500 + 10; 7 8 int vis [maxn], Match [maxn]; 9 int map [maxn] [maxn], Mark [maxn] [maxn]; 10 int CNT, maxmatch; // CNT: Number of vertices maxmatch: Maximum number of matches 11 12 int dx [] = {0, 0, 1,-1}; 13 int dy [] = {1, -1, 0, 0}; 14 15 int DFS (int x) 16 {17 for (INT I = 1; I <= cnt-1; I ++) 18 {19 if (! Vis [I] & map [x] [I]) 20 {21 vis [I] = 1; 22 if (! Match [I] | DFS (Match [I]) 23 {24 Match [I] = x; 25 return 1; 26} 27} 28} 29 return 0; 30} 31 32 void Hungary () 33 {34 maxmatch = 0; 35 for (INT I = 1; I <= cnt-1; I ++) 36 {37 memset (VIS, 0, sizeof (VIS); 38 maxmatch + = DFS (I); 39} 40} 41 42 int main () 43 {44 int T, H, W; 45 while (scanf ("% d", & T )! = EOF) 46 {47 While (t --) 48 {49 scanf ("% d", & H, & W); 50 char ch; 51 CNT = 1; 52 memset (mark, 0, sizeof (Mark); 53 memset (MAP, 0, sizeof (MAP); 54 memset (match, 0, sizeof (MATCH )); 55 56 for (INT I = 0; I 

 

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.