Minimum coverage path of poj 3020

Source: Internet
Author: User
/* The minimum path of poj 3020 overwrites the question and does not understand the idea at the beginning. Refer to the online code, this is the problem of least path coverage. O indicates that the antenna does not need to be overwritten. * It indicates that the antenna needs to be overwritten. One antenna can benefit two adjacent * points, ask the minimum number of antennas required to cover all * points with the minimum path overwrite of the undirected bipartite graph = point-Max match/2 modeling process: view each * point as a point, split points */# include <cstdio> # include <cstring> using namespace STD; # define maxn 405int t; int H, W; int count; int dir [4] [2] = {0, 1, 0,-1, 0,-1}; int map [41] [11]; int link [maxn] [maxn]; bool vis [maxn]; int match [maxn]; bool find (int x) {for (INT I = 1; I <= count-1; I ++) {If (! Vis [I] & link [x] [I]) {vis [I] = 1; if (find (Match [I]) | match [I] = 0) {match [I] = x; return true ;}}return false;} int MMG () {int ans = 0; memset (match, 0, sizeof (MATCH); For (INT I = 1; I <= count-1; I ++) {memset (VIS, 0, sizeof (VIS); If (find (I) ans ++;} return ans;} int main () {scanf ("% d", & T ); while (t --) {scanf ("% d", & H, & W); memset (MAP, 0, sizeof (MAP); memset (link, 0, sizeof (Link); char C [maxn]; Count = 1; For (INT I = 1; I <= H; I ++) {scanf ("% s", c); For (Int J = 1; j <= W; j ++) C [J-1] = '*'? Map [I] [J] = count ++: 0;} // For (INT I = 1; I <= H; I ++) // {// For (Int J = 1; j <= W; j ++) // printf ("% d", map [I] [J]); // printf ("\ n"); // while (1) {}for (INT I = 1; I <= H; I ++) for (Int J = 1; j <= W; j ++) {If (Map [I] [J]) {for (int K = 0; k <4; k ++) {int x = I + dir [k] [0], y = J + dir [k] [1]; If (Map [x] [Y]) link [map [I] [J] [map [x] [Y] = 1 ;}} int ans = MMG (); printf ("% d \ n", Count-1-(ANS/2 ));}}

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.