POJ 3020-antenna Placement (binary graph matching _ min path overlay + forward star composition)

Source: Internet
Author: User

Antenna Placement
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 6930 Accepted: 3439

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

Test instructions: In a h*w matrix, * represents the city, O represents the open space, the city needs to cover the wireless network, if you place a base station, can cover the adjacent two cities, ask the minimum number of base stations to be placed to cover all the city.

Idea: This problem is not a two-point map, but it is the problem of building maps. Is there a map or a graph, because the two map is different, the problem is a graph, this is not the city's X, y coordinates as a point set, but a city as a point set, the construction method is as follows (go)

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)

"Split (I think copy more accurate)" to each vertex of the original graph G is 2 points, which belong to the two vertex sets of the binary graph to be constructed.

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.

#include <stdio.h> #include <string.h> #include <stdlib.h> #include <iostream> #include <    Algorithm>using namespace std;struct Node {int v,w; int next;} Edge[10010];int cnt,k;int head[500];int vis[500];int link[500];int map[100][100];int jx[]= { -1,0,1,0};int jy[]= {0,1,0,    -1};void Add (int u,int v,int W) {edge[cnt].v=v;    Edge[cnt].w=w;    Edge[cnt].next=head[u]; head[u]=cnt++;}    int dfs (int u) {int i;        for (i=head[u]; i!=-1; i=edge[i].next) {int v=edge[i].v;            if (!vis[v]) {vis[v]=1; if (link[v]==-1| |                DFS (Link[v])) {link[v]=u;            return 1; }}} return 0;}    int main () {int t,i,j,l;    int h,w;    Char str;    scanf ("%d", &t);        while (t--) {memset (head,-1,sizeof (head));        memset (link,-1,sizeof (link));        memset (map,0,sizeof (map));        k=0;        cnt=0;        scanf ("%d%d", &h,&w); For (I=1, i<=h; i++) {for (J=1; j<=w;                J + +) {cin>>str;            if (str== ' * ') map[i][j]=++k;                    }} for (I=1, i<=h; i++) {for (j=1; j<=w; J + +) {if (Map[i][j]) {                                for (l=0; l<4; l++) {if (Map[i+jx[l]][j+jy[l]]) {                                Add (map[i][j],map[i+jx[l]][j+jy[l]],1);                            Add (map[i+jx[l]][j+jy[l]],map[i][j],1);        }}}}} int sum=0;            for (i=1;i<=k;i++) {memset (vis,0,sizeof (VIS));        Sum+=dfs (i); } printf ("%d\n", K-SUM/2);//non-binary graph: Minimum path cover number = "Split" The number of vertices of the original map-maximum number of matches/2}




POJ 3020-antenna Placement (binary graph matching _ min path overlay + forward star 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.