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(){;}

最新文章

  1. 创建docker私人仓库
  2. 安装redis入门
  3. linux进程命令
  4. Unity中Instantiate一个prefab时需要注意的问题
  5. 转 Eric Raymond对于几大开发语言的评价
  6. CAS实践笔录
  7. AngularJs学习笔记--html compiler
  8. 数据结构---顺序表(C++)
  9. Javascript 中的变量
  10. 常用Select语句
  11. Java 反射 Method threw &#39;java.lang.InstantiationException&#39; exception.
  12. Xcode7 真机免证书调试Cocos2D游戏
  13. Vue.set() this.$set()引发的视图更新思考
  14. 变量类型-Number
  15. Docker 随 docker服务重启
  16. MySQL程序之mysql参数详解
  17. Windows 下 Docker 的简单学习使用过程之二 Docker For windows
  18. AWS CSAA -- 02 AWS - 10000 Feet Overview
  19. js对金额浮点数运算精度的处理方案
  20. Android之HttpPost与HttpGet使用

热门文章

  1. sdoi2013 spring(hash+容斥)
  2. 四、分布式 Git(未完待续)
  3. 阿里云Linux系统安装配置Tomcat方法
  4. Java并发和多线程4:使用通用同步工具CountDownLatch实现线程等待
  5. VUE:项目的创建、编写、打包及规范检查
  6. 2、Koa2 路由+cookie
  7. 【codeforces 794A】Bank Robbery
  8. Jquery学习总结(2)——jQuery Ajax用法详解
  9. UESTC 1143 数据传输 网络流 最大流 Dinic
  10. Picking up Jewels