(N x M)-K <= 50 ).
Each feasible point is connected to the feasible point above and down, and a bipartite graph is obtained, and then directly
The maximum match, but the results are problematic and the analysis is not thorough. The duplicate edge is displayed, and the subscript between adjacent blocks is analyzed.
And there is a parity relationship, so only the even or odd point can be used to create a graph.
[Csharp]
# Include "stdio. h"
# Include "string. h"
# Define N 110
Struct node
{
Int x, y;
} Aa [51];
Int hash [N] [N], a [N] [N];
Int map [N] [N], v [N], mark [N];
Int n, m, cnt;
Int dx [4] = {1,-1, 0 };
Int dy [4] = {0, 0, 1,-1 };
Void get_map ()
{
Int I, j, k, x, y;
Scanf ("% d", & k );
Memset (hash, 0, sizeof (hash ));
While (k --)
{
Scanf ("% d", & x, & y );
Hash [x] [y] = 1;
}
Cnt = 1;
For (I = 1; I <= n; I ++)
{
For (j = 1; j <= m; j ++)
If (hash [I] [j] = 0)
{
A [I] [j] = cnt;
Aa [cnt]. x = I;
Aa [cnt]. y = j;
Cnt ++;
}
}
Memset (map, 0, sizeof (map ));
For (I = 1; I <= n; I ++)
{
For (j = 1; j <= m; j ++)
If (hash [I] [j] = 0)
{
For (k = 0; k <4; k ++)
{
X = I + dx [k];
Y = j + dy [k];
If (x> = 1 & x <= n & y> = 1 & y <= m & hash [x] [y] = 0)
{
Map [a [I] [j] [a [x] [y] = 1;
Map [a [x] [y] [a [I] [j] = 1;
}
}
}
}
}
Int dfs (int k)
{
Int I;
For (I = 1; I <cnt; I ++)
{
If (aa [I]. x + aa [I]. y) % 2 = 1)
Continue;
If (map [k] [I] &! V [I])
{
V [I] = 1;
If (mark [I] =-1 | dfs (mark [I])
{
Mark [I] = k;
Return 1;
}
}
}
Return 0;
}
Void output ()
{
Int I;
For (I = 1; I <cnt; I ++)
If (mark [I]! =-1)
Printf ("(% d, % d) -- (% d, % d) \ n", aa [I]. x, aa [I]. y, aa [mark [I]. x, aa [mark [I]. y );
}
Void solve ()
{
Int I, count;
Count = 0;
Memset (mark,-1, sizeof (mark ));
For (I = 1; I <cnt; I ++)
{
If (aa [I]. x + aa [I]. y) % 2 = 0)
Continue;
Memset (v, 0, sizeof (v ));
If (dfs (I) www.2cto.com
Count ++;
}
Printf ("% d \ n", count );
Output ();
Printf ("\ n ");
}
Int main ()
{
While (scanf ("% d", & n, & m )! =-1)
{
If (! N &&! M)
Break;
Get_map ();
Solve ();
}
Return 0;
}
Author: yyf572132811