POJ topic 3020 Antenna Placement (two-part picture)

Source: Internet
Author: User

Antenna Placement
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 7011 Accepted: 3478

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

AC Code

#include <stdio.h> #include <string.h>int map[1010][1010],cut[1010][1010];int link[101000],vis[101000], X,y,cnt;char str[1010][1010];int dfs (int u) {int i;for (i=1;i<=cnt;i++) {if (!vis[i]&&map[u][i]) {vis[i]=1; if (link[i]==-1| | DFS (Link[i])) {Link[i]=u;return 1;}}} return 0;} int main () {int t;scanf ("%d", &t), while (t--) {int n,m,i,j;scanf ("%d%d", &n,&m), and for (i=0;i<n;i++) {scanf ( "%s", Str[i]);} int X=0cnt=0;memset (cut,0,sizeof (cut)); for (i=0;i<n;i++) {for (j=0;j<m;j++) {if (str[i][j]== ' * ') cut[i][j]=++ CNT;}} memset (map,0,sizeof (map)); for (i=0;i<n;i++) {for (j=0;j<m;j++) {if (Cut[i][j]) {if (j>0&&cut[i][j-1] ) map[cut[i][j]][cut[i][j-1]]=1;if (I>0&&cut[i-1][j]) map[cut[i][j]][cut[i-1][j]]=1;if (j<m-1& &AMP;CUT[I][J+1]) map[cut[i][j]][cut[i][j+1]]=1;if (i<n-1&&cut[i+1][j]) map[cut[i][j]][cut[i+1][j]]=1;}} memset (link), int ans=0;for (i=1;i<=cnt;i++) {memset (vis,0,sizeof (VIS)), if (Dfs (i)) ans++;} printf ("%d\n", CNT-ANS/2);}}


POJ topic 3020 Antenna Placement (two-part picture)

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.