博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU-1507-Uncle Tom's Inherited Land*
阅读量:6887 次
发布时间:2019-06-27

本文共 3269 字,大约阅读时间需要 10 分钟。

链接:

题意:

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). 

思路:

根据矩阵x,y的和建立二分图,同时不处理池塘。

输出路径根路据Link数组,找到每个边对应左端点的编号,同时结构体排序,使编号小的在前,再遍历数组查找即可。

代码:

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;typedef long long LL;const int MAXN = 1e4+10;int Next[4][2] = { {-1, 0}, {0, 1}, {1, 0}, {0, -1}};struct Node{ int x, y; int pos; Node(int x, int y, int pos):x(x), y(y), pos(pos){} bool operator < (const Node & that)const { return this->pos < that.pos; }};vector
G[MAXN];int Dis[200][200];int Link[MAXN], Vis[MAXN];int n, m, k;int mid;int cnt1, cnt2;void Init(){ for (int i = 1;i <= n;i++) G[i].clear();}bool Dfs(int x){ for (int i = 0;i < G[x].size();i++) { int node = G[x][i]; if (Vis[node] == 0) { Vis[node] = 1; if (Link[node] == -1 || Dfs(Link[node])) { Link[node] = x; return true; } } } return false;}int Solve(){ memset(Link, -1, sizeof(Link)); int cnt = 0; for (int i = 1;i <= cnt1;i++) { memset(Vis, 0, sizeof(Vis)); if (Dfs(i)) cnt++; } return cnt;}int main(){ while (~scanf("%d%d", &n, &m) && n) { cnt1 = cnt2 = 0; memset(Dis, 0, sizeof(Dis)); cin >> k; int x, y; for (int i = 1;i <= k;i++) { cin >> x >> y; Dis[x][y] = -1; } for (int i = 1;i <= n;i++) { for (int j = 1;j <= m;j++) { if (Dis[i][j] != -1) { if ((i+j)%2 == 1) Dis[i][j] = ++cnt1; else Dis[i][j] = ++cnt2; } } } for (int i = 1;i <= n;i++) { for (int j = 1;j <= m;j++) { if ((i+j)%2 == 1 && Dis[i][j] != -1) { for (int k = 0;k < 4;k++) { int tx = i+Next[k][0]; int ty = j+Next[k][1]; if (tx < 1 || tx > n || ty < 1 || ty > m) continue; if (Dis[tx][ty] == -1) continue; G[Dis[i][j]].push_back(Dis[tx][ty]); } } } } int res = Solve(); set
kv; for (int i = 1;i <= n;i++) { for (int j = 1;j <= m;j++) { if ((i+j)%2 == 0 && Dis[i][j] != -1 && Link[Dis[i][j]] != -1) { kv.emplace(i, j, Link[Dis[i][j]]); } } } cout << res << endl; auto it = kv.begin(); for (int i = 1;i <= n;i++) { for (int j = 1;j <= m;j++) { if ((i+j)%2 == 1 && Dis[i][j] == it->pos) { printf("(%d,%d)--(%d,%d)\n", i, j, it->x, it->y); ++it; } } } for (int i = 1;i <= cnt1;i++) G[i].clear(); } return 0;}

  

转载于:https://www.cnblogs.com/YDDDD/p/10871591.html

你可能感兴趣的文章
popwindow
查看>>
FastSocket学习笔记~RPC的思想,面向对象的灵活
查看>>
TCP连接探测中的Keepalive 和心跳包
查看>>
2015第5周三网摘
查看>>
C#系列教程——对一个对象的装箱取消转换
查看>>
RTP协议分析
查看>>
簡單SQL存儲過程實例
查看>>
有效沟通:听懂话,才能回答(转)
查看>>
整理的代码规范
查看>>
IOS之UI--小实例项目--添加商品和商品名(使用xib文件终结版) + xib相关知识点总结...
查看>>
小知识~让你的DLL类库带上注释
查看>>
Junit测试打印详细的log日志,可以看到sql
查看>>
还是畅通工程
查看>>
深入分析Kubernetes Critical Pod(四)
查看>>
docker安装mongodb
查看>>
第69天:jQuery入口函数
查看>>
redis集群搭建
查看>>
如何在阿里云上构建一个合适的Kubernetes集群
查看>>
那些著名网站的90年代(转)
查看>>
lvs主备NAT模式上课用例(keepalived)
查看>>