POJ1548 Robots "Minimum path overlay of the binary graph"

Source: Internet
Author: User

Topic Links:

http://poj.org/problem?id=1548


Main topic:

in a n*m (N <= 24,m <= 24) Figure, there is a lot of rubbish, and the robot that cleans the rubbish starts from the upper left corner. have been

know that the robot can only clean the rubbish to the right or down, after cleaning up a place to continue to the right or down to clear Management

Other rubbish. End-of-run to (n,m) position terminated. Q: The minimum number of robots required to clean up all the rubbish.


Ideas:

The figure does not give the size of N and M, just gives the location of the rubbish. The input ends with 0 0 for a set of data inputs. Build a structure

To store the garbage's coordinate values. Now to build a binary map, the two sides of the graph is the garbage node, traverse the original, if Garbage J in

in the lower right corner of the garbage I, the (i,j) is added to the binary diagram, and the problem becomes: the minimum path coverage of the binary graph is obtained. by two

Min -Path overlay = Point-two graph maximum matching, according to the Hungarian algorithm to calculate the maximum matching of two, and then to obtain the knot The results.


AC Code:

#include <iostream> #include <algorithm> #include <cstdio> #include <cstring>using namespace    std;const int MAXN = 600;struct node{int x; int y;} Point[maxn];bool map[maxn][maxn],mask[maxn];int nx,ny;int cx[maxn],cy[maxn];int FindPath (int u) {for (int i = 0; i < NY; ++i) {if (Map[u][i] &&!            Mask[i]) {mask[i] = 1; if (cy[i] = =-1 | |                Findpath (Cy[i])) {Cy[i] = u;                Cx[u] = i;            return 1; }}} return 0;}    int Maxmatch () {for (int i = 0; i < NX; ++i) cx[i] = 1;    for (int i = 0; i < NY; ++i) cy[i] = 1;    int res = 0;                for (int i = 0, i < NX; ++i) {if (cx[i] = = 1) {for (int j = 0; j < NY; ++j)            MASK[J] = 0;        Res + = Findpath (i); }} return res;}    int main () {int id = 0; while (scanf ("%d%d", &point[id].x,&point[id].y) && (point[id].x!=-1 && point[id].y!=-1)) {id++; while (scanf ("%d%d", &point[id].x,&point[id].y) && (point[id].x| |        POINT[ID].Y)) id++;        memset (map,0,sizeof (MAP)); for (int i = 0, i < ID; ++i) {for (int j = i+1; j < ID; ++j) {if (point[i                ].x <= point[j].x && point[i].y <= point[j].y) map[i][j] = 1;            else if (point[i].x >= point[j].x && point[i].y >= point[j].y) map[j][i] = 1;        }} NX = NY = ID;        printf ("%d\n", Id-maxmatch ());    id = 0; } return 0;}


POJ1548 Robots "Minimum path overlay of the binary graph"

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.