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

本文共 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

你可能感兴趣的文章
IOS的 new Date()格式化问题
查看>>
sharepoint webpart 获取文档库下的所有文件夹名
查看>>
java数据结构和算法--------第六章
查看>>
关于php如何连贯操作类方法(以数据库为例)
查看>>
25th SEP, 要好好的走下去
查看>>
BZOJ4822[Cqoi2017]老C的任务——树状数组(二维数点)
查看>>
BZOJ1299[LLH邀请赛]巧克力棒——Nim游戏+搜索
查看>>
未能为 SSL/TLS 安全通道建立信任的解决办法
查看>>
cmake是什么
查看>>
使用MASM10(变量的使用)- Win32汇编语言018
查看>>
【Docker学习笔记】----基于centos 7 的Docker安装
查看>>
Android笔记之OnLongClickListener
查看>>
Java客户端:调用EyeKey HTTP接口进行人脸对比
查看>>
SQL之分区函数
查看>>
创业公司如何实施敏捷开发
查看>>
Django使用AJAX调用自己写的API接口
查看>>
数据科学求职准备
查看>>
Wireshark抓包工具使用教程以及常用抓包规则
查看>>
fedora16下更改网卡名字
查看>>
awk中NF,NR的含义
查看>>