Poj 3020 antenna placement (bipartite graph creation training + minimum path coverage)

Source: Internet
Author: User


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


Antenna placement
Time limit:1000 ms   Memory limit:65536 K
Total submissions:6692   Accepted:3325

Description

The global aerial research centre has been allotted the task of building the maximum th generation of mobile phone nets in Sweden. the most striking reason why they got the job, is their discovery of a new, highly noise resistant, antenna. it is called 4 dair, and comes in four types. each type can only transmit and receive signals in a direction aligned with a (slightly skewed) latitudinal and longitudinal 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 an example picture of places of interest, depicted by twelve small rings, and nine 4 Dair antennas depicted by ellipses covering them.



Question: Given a map, * represents a city, and O represents an open space. The antenna is used to cover two adjacent cities. How many antennas do I need at least? (The so-called adjacent refers to the top, bottom, and left adjacent to Four Directions)


The meaning of the question is very clear. Find the minimum path coverage of the Bipartite Graph. The difficulty is to build the graph... Good luck today. The idea of creating a graph comes from zoj1654.

PS. It covers the city, not the open space. At first, I was wrong.


Ideas: Today, zoj 1654, which is about the same as 1654, uses the block-based idea. This idea uses a single city as a block and numbers it to build graph connectivity, as for the final output result, the total number of cities minus the maximum number of matching = the number of remaining cities, that is, the maximum number of independent sets. The number of remaining cities indicates that they cannot be augmented/matched, then we need to build an antenna separately, and the matching number/2 = one antenna covers two cities

So eventually answer = city-ans + ANS/2

Zoj 1654 AC code


Accepted 1584 k 16 Ms C ++

If you want to understand it, open it and try again, 1a


# Include <iostream> # include <cstdio> # include <cstdlib> # include <cstring> # include <algorithm> # include <math. h> # define Init (a) memset (A, 0, sizeof (A) # define PI ACOs (-1, 0) using namespace STD; const int maxn = 60; const int maxm = 600; # define lson left, M, id <1 # define rson m + 1, right, id <1 | 1 # define min (A, B) (A> B )? B: A # define max (A, B) (A> B )? A: bint ma [maxn] [maxn]; char map [maxn] [maxn]; int G [maxm] [maxm]; int line [maxm]; bool vis [maxm]; int MV [4] [2] = {}, {-}, {}, {0,-1}; int N, m, city; int DFS (int u) {for (INT v = 1; v <= city; V ++) {If (G [u] [v] = 1 &&! Vis [v]) {vis [v] = 1; if (line [v] =-1 | DFS (line [v]) {line [v] = u; return 1 ;}} return 0 ;}int K_m () {int ans = 0; memset (line,-1, sizeof (line); For (INT I = 1; I <= city; I ++) {Init (VIS); ans + = DFS (I );} return ans;} void get_g (int I, Int J) // figure {for (INT dir = 0; Dir <4; Dir ++) {int wx = I + MV [dir] [0]; int WY = J + MV [dir] [1]; if (Map [wx] [WY] = '*') {G [ma [I] [J] [ma [wx] [WY] = 1; // build a connection between the current city and its four adjacent cities }}} Int main () {int t; scanf ("% d", & T); char a [500]; while (t --) {scanf ("% d", & N, & M); City = 0; gets (a); // if no value is added, the test data cannot be read ..... I am particularly speechless Init (MA); Init (g); For (INT I = 0; I <n; I ++) {gets (Map [I]); for (Int J = 0; j <m; j ++) {If (Map [I] [J] = '*') ma [I] [J] = ++ city; // Number of all cities }}for (INT I = 0; I <n; I ++) {for (Int J = 0; j <m; j ++) {If (Map [I] [J] = '*') {get_g (I, j ); // construct a bipartite graph }}int ans = K_m (); // printf ("cisy = % d ans = % d \ n", city, ANS ); // a match is equivalent to overwriting printf ("% d \ n", city-ans + ANS/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.