Antenna Placement (Hungarian algorithm, least path overlay)

Source: Internet
Author: User

Antenna Placement
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 6991 Accepted: 3466

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

Source

Svenskt Mästerskap I programmering/norgesmesterskapet 2001 Minimum path overlay for a non-binary graph = number of vertices – maximum binary match/2; details, click here
1#include <stdio.h>2#include <iostream>3#include <queue>4#include <string.h>5 using namespacestd;6 BOOLmap[ -][ -] ;7 intvis[ -][ -] ;8 inta[ -][ -] ;9 intGirl [ -] ;Ten BOOLsta[ -] ; One intCNT; A intRow, col; - Charst[ -] ; - intmove[][2] = {1,0,0,1, -1,0,0, -1} ; the  - BOOLHungary (intx) - { -      for(inti =1; I <= CNT; i++) { +         if(Map[x][i] && sta[i] = =false) { -Sta[i] =true ; +             if(Girl[i] = =0||Hungary (Girl[i])) { AGirl[i] =x; at                 return true ; -             } -         } -     } -     return false ; - } in  - intMain () to { +    //freopen ("A.txt", "R", stdin); -     intT; theCIN >>T; *      while(t--) { $scanf ("%d%d", &row, &col);Panax Notoginseng GetChar (); -CNT =0 ; thememset (Vis,-1,sizeof(Vis)); +memset (Map,0,sizeof(map)); AMemset (A,-1,sizeof(a)); theMemset (Girl,0,sizeof(Girl)); +          for(inti =0; i < row; i++) { - gets (ST); $              for(intj =0; J < Col; J + +) { $                if(St[j] = ='*') { -A[i +1][j +1] =1+ cnt++; -                } the             } -         }Wuyi        /*for (int i = 1; I <= row; i++) { the For (int j = 1; J <= Col; j + +) { - printf ("%d", a[i][j]); Wu             } - puts (""); About         }*/ $          for(inti =1; I <= row; i++) { -              for(intj =1; J <= Col; J + +) { -                 if(A[i][j]! =-1) { -                      for(intK =0; K <4; k++) { A                         intx = i + move[k][0] ; +                         inty = j + move[k][1] ; the                         if(A[x] [y]! =-1) -map[a[i][j] [a[x][y]] =1 ; $                     } the                 } the             } the         } the        /*for (int i = 1; I <= cnt; i++) { - For (int j = 1; J <= CNT; j + +) { in printf ("%d", map[i][j]); the             } the puts (""); About         }*/ the         intall =0 ; the          for(inti =1; I <= CNT; i++) { thememset (STA,0,sizeof(STA)); +             if(Hungary (i)) -All + + ; the         }Bayi       //printf ("cnt =%d, all =%d\n", cnt, all); theprintf ("%d\n", Cnt-all/2) ; the     } -     return 0 ; -}
View Code

Antenna Placement (Hungarian algorithm, least path overlay)

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.