HDU——T 1507 Uncle Tom's Inherited Land*

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU——T 1507 Uncle Tom's Inherited Land*相关的知识,希望对你有一定的参考价值。

http://acm.hdu.edu.cn/showproblem.php?pid=1507

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3671    Accepted Submission(s): 1554
Special Judge


Problem Description
Your old uncle Tom inherited a piece of land from his great-great-uncle. Originally, the property had been in the shape of a rectangle. A long time ago, however, his 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 be sure, for you have not been to the place, but he may have made so many ponds that the land may now consist of several disconnected islands.)

Your uncle Tom wants to sell the inherited land, but local rules now regulate property sales. Your uncle has been informed that, at his great-great-uncle‘s request, a law has been passed which establishes that property can only be sold in rectangular lots the size of two squares of your uncle‘s property. Furthermore, ponds are not salable property.

Your uncle asked your help to determine the largest number of properties he could sell (the remaining squares will become recreational parks). 
技术分享
 

 

Input
Input will include several test cases. The first line of a test case contains two integers N and M, representing, respectively, the number of rows and columns of the land (1 <= N, M <= 100). The second line will contain an integer K indicating the number of squares that have been turned into ponds ( (N x M) - K <= 50). Each of the next K lines contains two 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.
 

 

Output
For 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 are 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 4 6 1 1 1 4 2 2 4 1 4 2 4 4 4 3 4 4 2 3 2 2 2 3 1 0 0
 

 

Sample Output
4 (1,2)--(1,3) (2,1)--(3,1) (2,3)--(3,3) (2,4)--(3,4) 3 (1,1)--(2,1) (1,2)--(1,3) (2,3)--(3,3)
 

 

Source
 

 

Recommend
LL   |   We have carefully selected several similar problems for you:  1281 1528 1151 1498 1533 
 
 
黑白奇偶染色建图。。
wocao  sumvis每次初始改为0就错,不清空就A了啊啊啊
 1 #include <cstring>
 2 #include <cstdio>
 3 
 4 using namespace std;
 5 
 6 const int N(110);
 7 int fx[4]={1,0,-1,0};
 8 int fy[4]={0,1,0,-1};
 9 bool lose[N][N];
10 int n,m,ans,sumvis;
11 int vis[N][N],match[N][N][2];
12 
13 bool find(int x,int y)
14 {
15     for(int xx,yy,i=0;i<4;i++)
16     {
17         xx=fx[i]+x;yy=fy[i]+y;
18         if(!lose[xx][yy]&&vis[xx][yy]!=sumvis)
19         {
20             vis[xx][yy]=sumvis;
21             if(!match[xx][yy][0]||find(match[xx][yy][0],match[xx][yy][1]))
22             {
23                 match[xx][yy][0]=x;
24                 match[xx][yy][1]=y;
25                 return true;
26             }
27         }
28     }
29     return false;
30 }
31 
32 inline void init()
33 {
34     ans=0;
35     memset(vis,0,sizeof(vis));
36     memset(lose,0,sizeof(lose));
37     memset(match,0,sizeof(match));
38 }
39 
40 int AC()
41 {
42     for(int t,x,y;scanf("%d%d",&n,&m)&&n&&m;init())
43     {
44         for(scanf("%d",&t);t--;)
45             scanf("%d%d",&x,&y),lose[x][y]=1;
46         for(int i=0;i<=n;i++) lose[i][0]=lose[i][m+1]=1;
47         for(int i=0;i<=m;i++) lose[0][i]=lose[n+1][i]=1;
48         for(int i=1;i<=n;i++)
49             for(int j=1;j<=m;j++)
50             if((i+j)&1&&!lose[i][j])
51             {
52                 if(find(i,j)) ans++;
53                 sumvis++;
54             }
55         printf("%d\n",ans);
56         for(int i=1;i<=n;i++)
57           for(int j=1;j<=m;j++)
58             if(match[i][j][0])
59               printf("(%d,%d)--(%d,%d)\n",i,j,match[i][j][0],match[i][j][1]);
60         printf("\n");
61     }
62     return 0;
63 }
64 
65 int I_want_AC=AC();
66 int main(){;}

 

以上是关于HDU——T 1507 Uncle Tom's Inherited Land*的主要内容,如果未能解决你的问题,请参考以下文章

hdu1507——Uncle Tom&#39;s Inherited Land*

HDU 1507 Uncle Tom's Inherited Land*(二分图匹配)

「日常训练」Uncle Tom's Inherited Land*(HDU-1507)

HDU1507 Uncle Tom's Inherited Land* 二分图匹配 匈牙利算法 黑白染色

HDOJ 1507 Uncle Tom&#39;s Inherited Land*

Uncle Tom's Inherited Land*