POJ-3020 Antenna Placement Minimum path overlay

Source: Internet
Author: User

The main problem: There are N cities, to establish a radio station in these n cities, each radio station can only cover 2 neighboring cities, ask at least how many wireless power stations need to build

Problem-Solving ideas: English topic good pit, looked at half a day.
This problem is similar to POJ-2446 chessboard.
All cities can be divided into two point sets, then the connection between the radio station to represent the coverage of the relationship.
Because all cities have to be covered, so according to the relationship, find the smallest path coverage can cover all cities

#include <cstdio>#include <algorithm>#include <cstring>#include <vector>using namespace STD;Const intN = the;Const intM = -;intVis[n], link[n],g[m][m], H, W, CNT; vector<int>City[n];CharSTR[M];voidInit () {scanf("%d%d", &h, &w); CNT =0;memset(g,0,sizeof(g)); for(inti =1; I <= H; i++) {scanf('%s ', str); for(intj =0; J < W; J + +)if(Str[j] = =' * ') g[i][j+1] = ++cnt; } for(inti =1; I <= CNT; i++) city[i].clear (); for(inti =1; I <= H; i++) for(intj =1; J <= W; J + +)if(G[i][j]) {ifI1>0&& g[i-1][J]) City[g[i][j]].push_back (g[i-1][J]);if(i +1<= h && g[i+1][J]) City[g[i][j]].push_back (g[i+1][J]);if(J-1>0&& g[i][j-1]) City[g[i][j]].push_back (g[i][j-1]);if(j +1<= W && g[i][j+1]) City[g[i][j]].push_back (g[i][j+1]); }memset(Link,0,sizeof(link));}BOOLDfsintu) { for(inti =0; I < city[u].size (); i++) {intv = city[u][i];if(Vis[v])Continue; VIS[V] =1;if(!link[v] | | DFS (LINK[V)) {Link[v] = u;return true; }    }return false;}voidHungary () {intAns =0; for(inti =1; I <= CNT; i++) {memset(Vis,0,sizeof(VIS));if(Dfs (i)) ans++; }printf("%d\n", Cnt-ans/2);}intMain () {intTestscanf("%d", &test); while(test--)        {init ();    Hungary (); }return 0;}

POJ-3020 Antenna Placement Minimum 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.