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了啊啊啊
 #include <cstring>
#include <cstdio> using namespace std; const int N();
int fx[]={,,-,};
int fy[]={,,,-};
bool lose[N][N];
int n,m,ans,sumvis;
int vis[N][N],match[N][N][]; bool find(int x,int y)
{
for(int xx,yy,i=;i<;i++)
{
xx=fx[i]+x;yy=fy[i]+y;
if(!lose[xx][yy]&&vis[xx][yy]!=sumvis)
{
vis[xx][yy]=sumvis;
if(!match[xx][yy][]||find(match[xx][yy][],match[xx][yy][]))
{
match[xx][yy][]=x;
match[xx][yy][]=y;
return true;
}
}
}
return false;
} inline void init()
{
ans=;
memset(vis,,sizeof(vis));
memset(lose,,sizeof(lose));
memset(match,,sizeof(match));
} int AC()
{
for(int t,x,y;scanf("%d%d",&n,&m)&&n&&m;init())
{
for(scanf("%d",&t);t--;)
scanf("%d%d",&x,&y),lose[x][y]=;
for(int i=;i<=n;i++) lose[i][]=lose[i][m+]=;
for(int i=;i<=m;i++) lose[][i]=lose[n+][i]=;
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
if((i+j)&&&!lose[i][j])
{
if(find(i,j)) ans++;
sumvis++;
}
printf("%d\n",ans);
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
if(match[i][j][])
printf("(%d,%d)--(%d,%d)\n",i,j,match[i][j][],match[i][j][]);
printf("\n");
}
return ;
} int I_want_AC=AC();
int main(){;}

HDU——T 1507 Uncle Tom's Inherited Land*的更多相关文章

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

    Uncle Tom's Inherited Land* Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  2. Hdu 1507 Uncle Tom's Inherited Land* 分类: Brush Mode 2014-07-30 09:28 112人阅读 评论(0) 收藏

    Uncle Tom's Inherited Land* Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  3. HDU 1507 Uncle Tom's Inherited Land*(二分匹配,输出任意一组解)

    Uncle Tom's Inherited Land* Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  4. HDU 1507 Uncle Tom's Inherited Land(最大匹配+分奇偶部分)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1507 题目大意:给你一张n*m大小的图,可以将白色正方形凑成1*2的长方形,问你最多可以凑出几块,并输 ...

  5. HDU 1507 Uncle Tom's Inherited Land*

    题目大意:给你一个矩形,然后输入矩形里面池塘的坐标(不能放东西的地方),问可以放的地方中,最多可以放多少块1*2的长方形方块,并输出那些方块的位置. 题解:我们将所有未被覆盖的分为两种,即分为黑白格( ...

  6. hdu-----(1507)Uncle Tom's Inherited Land*(二分匹配)

    Uncle Tom's Inherited Land* Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  7. Uncle Tom's Inherited Land*

    Uncle Tom's Inherited Land* Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java ...

  8. XTU 二分图和网络流 练习题 B. Uncle Tom's Inherited Land*

    B. Uncle Tom's Inherited Land* Time Limit: 1000ms Memory Limit: 32768KB 64-bit integer IO format: %I ...

  9. hdu1507 Uncle Tom's Inherited Land* 二分匹配

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1507 将i+j为奇数的构成x集合中 将i+j为偶数的构成y集合中 然后就是构建二部图 关键就是构图 然 ...

随机推荐

  1. BZOJ 2244 [SDOI2011]拦截导弹 (三维偏序CDQ+线段树)

    题目大意: 洛谷传送门 不愧为SDOI的duliu题 第一问?二元组的最长不上升子序列长度?裸的三维偏序问题,直接上$CDQ$ 由于是不上升,需要查询某一范围的最大值,并不是前缀最大值,建议用线段树实 ...

  2. Layui表格编辑【不依赖Layui的动态table加载】

    依赖jquer,layui/css <td class="My_edit"></td> Jquery代码 //-----[Layui表格编辑(<td ...

  3. Android开发进度03

    1,今日:目标:实现登录界面 2,昨天:实现第一个Android项目Helloworld 3,收获:会使用手机进行测试,会使用SQlite数据库 4,问题:创建项目时出错

  4. C#调用带结构体指针的C Dll的方法【转】

    发现一篇文章关于C#调用DALL动态链接库的函数的,复制下来学习用.感谢作者的分析,原文传送门:https://www.cnblogs.com/ye-ming/p/8004314.html 在C#中调 ...

  5. HDU——T 1498 50 years, 50 colors

    http://acm.hdu.edu.cn/showproblem.php?pid=1498 Time Limit: 2000/1000 MS (Java/Others)    Memory Limi ...

  6. window8.1 CenterOS 双系统

    window8.1 CenterOS 双系统 学习了: http://blog.csdn.net/ac_hell/article/details/53436890 https://jingyan.ba ...

  7. web前端project师知识汇总

    分类: Web开发应用  一.何为Web前端project师?           前端project师,也叫Web前端开发project师.他是随着web发展.细分出来的行业.Web前端开发proj ...

  8. js判断是对象还是集合

    /*============================================ 函数功能:对返回数据中的列表数据进行非空处理 ============================== ...

  9. [jzoj NOIP2018模拟11.02]

    嗯T1忘记取模了,100到20 嗯T2忘记了那啥定理,暴力也写炸了,这题我认 嗯T3线段树合并分裂没有写炸,考场上就知道妥妥的70分.但是,分数出的时候听到有人说暴力也是70分,我???脸黑,枉我敲了 ...

  10. 【DNN】 安装问题

    http://blog.csdn.net/hwt0101/article/details/9153083 这是IIS 注册的问题  IIS 在安装VS 之前就装上了,所以 没有注册是上 F4 从新卸载 ...