Uncle Tom ' s inherited land*
Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 2496 Accepted Submission (s): 1028
Special Judge
Problem descriptionyour old Uncle Tom inherited a piece of the land from his great-great-uncle. Originally, the property had been in the shape of a rectangle. A long time ago, however, he great-great-uncle decided to divide the land into a grid of small squares. He turned some of the squares into ponds, for he loved to hunt ducks and wanted to attract them to his property. (You cannot is sure, for you has not been to the place, but he may has made so many ponds then the land could now consist of several disconnected islands.)
Your Uncle Tom wants to sell the inherited land, but local rules now regulate property sales. Your uncle had been informed that, at his great-great-uncle's request, a law had been passed which establishes that proper Ty can only is sold in rectangular lots the size of the squares of your uncle ' s property. Furthermore, ponds is not the Salable property.
Your Uncle asked Your help to determine the largest number of properties he could sell (the remaining squares would become Recreational parks).
Inputinput would include several test cases. The first line of a test case contains, integers N and M, representing, respectively, the number of rows and columns of The Land (1 <= N, M <= 100). The second line would contain an integer k indicating the number of squares that has been turned into ponds ((N x M)-K <= 50). Each of the next K lines contains, integers X and Y describing the position of a square which was turned into a pond (1 <= X <= N and 1 <= Y <= M). The end of input is indicated by N = M = 0.
Outputfor each test case in the input your program should first output one line, containing an integer p representing the Maximum number of properties which can be sold. The next P lines specify each pair of squares which can be sold simultaneity. If there is more than one solution, anyone is acceptable. There is a blank line after each test case. See sample below for clarification of the output format.
Sample Input
4 461 11 42 24 14 24 44 344 23 22 23 10 0
Sample Output
4 (1,3)-(2,1)-(3,1) (2,3)-(3,3) (2,4)-(3,4) 3 (a)-(2,1) (+)-(1,3) (2,3)-(3,3)
Sourcesouth America 2002-practice
Recommendll | We have carefully selected several similar problems for you:1281 1068 1528 1151 1150
topic Meaning:
Given a matrix lattice of n * m, the second row is given a K value for the pond, then the pond coordinates are given, and the requirement is to fill it with a small rectangle of 1 * 2 in the area that is not a pond and ask for a maximum number of small rectangles to fill.
This is about yesterday let me see a topic, said he how also can not find his bug, first of all, say my Code, the bipartite graph is a bit according to the points of the horizontal ordinate sums the parity of the division. Because if a small lattice is odd, then the adjacent lattice around him must be an even number. That is, only the adjacent lattice with the odd and even make up 1 * 2 small rectangles, then it is in line with the meaning of two, in essence, the maximum matching with the bipartite graph to find the maximum number of odd and even edge, these edges ensure that will not cross.
In order to facilitate the construction of the map, will all not land parts from 1......num ... Start the tag, and then enumerate any non-pond points, search around it, and save the binary map with the G array, then note that the G array can be up to n * m, or the value of the num-1 directly, that is, the number of small land squares. For how to output a matching edge, use a two-dimensional array or a struct pre "" "to denote the horizontal ordinate of a point value in the DIC array, then for all even squares if there is a match, that is from" I "! =-1, which equals the value of the right match point of the I point, and then queries its horizontal ordinate through the pre array.
See the code for details:
/*=============================================================================## Author:liangshu-cbam # # QQ : 756029571 # # School: Harbin Polytechnic University # # last modified:2015-08-27 10:36## filename:e.cpp## Description: # The people who is crazy enough to think they can change the world, is the ones who does! =============================================================================*/#include <iostream> # include<sstream> #include <algorithm> #include <cstdio> #include <string.h> #include <c ctype> #include <string> #include <cmath> #include <vector> #include <stack> #includ e<queue> #include <map> #include <set> using namespace std;const int inf=201; int cnt[inf][inf];int dic[inf][inf];int from[inf],tot;int pre[inf][2];bool use[inf];int dir[][2] = {{1,0},{0,1},{0,-1} , { -1,0}};vector<int>g[inf * INF]; int n, m; int num, bool match (int x) {for (int i=0;i<g[x].size (); i++) {if (!use[g[x][i]]) {use[g[x][i]]=1; if (from[g[x][i]]==-1| | Match (From[g[x][i])) {from[g[x][i]]=x; return 1; }}} return 0;} int Hungary () {tot=0; Memset (From,255,sizeof (from)); For (int. i=1;i<= num-1;i++) {memset (use,0,sizeof (use)); if (Match (i)) {++tot; }} return tot;} int main () {while (scanf ("%d%d", &n, &m)! = EOF && n + m) {int k; scanf ("%d", &k); memset (DIC, 0, sizeof (DIC)); memset (CNT, 0, sizeof (CNT)); memset (pre, 0, sizeof (pre)); for (int i = 1; I <= K; i++) {int x, y; scanf ("%d%d", &x, &y); Cnt[x][y] = 1; num = 1; for (int i = 1, i <= N; i++) {for (int j = 1; J <=m; J + +) {if (!cnt[i][j]) { pre[num][0] = i; Pre[num][1] = j; DIC[I][J] = num++; }}} for (int i = 1, i <= N; i++) {for (int j = 1; j <= M; j + +) { if (Dic[i][j]) if ((((i + j) & 1)) for (int k = 0; k < 4; k++) {int x = i + dir[k][0]; int y = j + dir[k][1]; if (x >= 1 && x <= n && y >=1 && y <=m && dic[x][y]) G[dic[i][j]].push_back (Dic[x][y]); }}} int ans = Hungary (); cout<<ans<<endl; for (int i = 1; I <= num-1; i++) {if (from[i]! =-1) {cout<< "(" <<pre[i][0]<< "," & lt;<pre[i][1]<< ")--" << "(" <<pre[from[i]][0]<< "," <<pre[from[i]][1]<< ") \ n"; }} for (int i = 1; I <= inf * INF; i++) g[i].clear (); cout<<endl; }}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Hangzhou Electric Hdu ACM Uncle Tom's inherited land* (binary graph matching modeling)