POJ
来源:互联网 发布:cocos jscompile 源码 编辑:程序博客网 时间:2024/06/02 04:54
题意
农夫的养牛场,是一个R 行C 列的矩形,一场大雨后,养牛场低洼的地方都有了积水。农夫的牛都很娇贵的,他们吃草的时候,不想把他们的蹄子给弄脏了。为了不让牛儿们把它们的蹄子弄脏,农夫决定把有水的地方铺上木板。他的木板是宽度为1,长度没有限制的。
他想用最少数目的木板把所有有水的低洼处给覆盖上,木板不能覆盖草地,但是可以重叠。
题解
找到每行连续的’*’,对每一块编号。再找到每列连续的,编号。每行的和每列的连边跑匈牙利即可
常数巨大的丑陋代码
# include <stdio.h># include <stdlib.h># include <iostream># include <string.h># include <algorithm>using namespace std;# define IL inline# define RG register# define UN unsigned# define ll long long# define rep(i, a, b) for(RG int i = a; i <= b; i++)# define per(i, a, b) for(RG int i = b; i >= a; i--)# define mem(a, b) memset(a, b, sizeof(a))# define max(a, b) (((a) > (b)) ? (a) : (b))# define min(a, b) (((a) < (b)) ? (a) : (b))# define Swap(a, b) a ^= b, b ^= a, a ^= b;IL ll Get(){ char c = '!'; ll z = 1, num = 0; while(c != '-' && (c < '0' || c > '9')) c = getchar(); if(c == '-') z = -1, c = getchar(); while(c >= '0' && c <= '9') num = num * 10 + c - '0', c = getchar(); return num * z;}const int MAXN = 501;int map[MAXN][MAXN], vis[MAXN], girl[MAXN], n, m, m1[MAXN][MAXN], m2[MAXN][MAXN];char land[MAXN][MAXN];IL int Dfs(RG int u){ rep(v, 1, m) if(map[u][v] && !vis[v]){ vis[v] = 1; if(girl[v] == -1 || Dfs(girl[v])){ girl[v] = u; return 1; } } return 0;}IL int Hungarian(){ RG int ans = 0; mem(girl, -1); rep(i, 1, n) mem(vis, 0), ans += Dfs(i); return ans;}int main(){ RG int x = Get(), y = Get(); rep(i, 1, x) rep(j, 1, y) scanf(" %c", &land[i][j]); rep(i, 1, x) rep(j, 1, y) if(land[i][j] == '*'){ n++; while(j <= y && land[i][j] == '*') m1[i][j++] = n; } rep(i, 1, y) rep(j, 1, x) if(land[j][i] == '*'){ m++; while(j <= x && land[j][i] == '*') m2[j++][i] = m; } rep(i, 1, x) rep(j, 1, y) if(land[i][j] == '*') map[m1[i][j]][m2[i][j]] = 1; printf("%d\n", Hungarian()); return 0;}
阅读全文
0 0
- POJ
- poj
- POJ
- POJ
- poj
- poj
- POJ
- POJ
- poj
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- PAT乙级 1010. 一元多项式求导 (25)
- VS2013 MFC做的文档中英文分拣(支持xml excel text格式)屏蔽字宏 游戏便捷小程序
- 常用的输入输出方法
- javascript程序块作用域
- LBP特征
- POJ
- [ulua]开发工具介绍
- HDU 2112 HDU Today(Floyd)
- HOG特征
- 表达式
- 平方和与立方和
- PAT 1027. 打印沙漏(20)
- 手把手教你如何搭建CTS测试环境---3、SDK安装和环境配置
- Queue、Deque和Stack