uva 12265 - Selling Land(dp)
来源:互联网 发布:遗传算法的函数 编辑:程序博客网 时间:2024/05/19 02:20
题目链接:uva 12265 - Selling Land
题目大意:给出一个图,要求以每个位置为右下角,找出最大周长的矩阵,然后统计所有周长的矩阵。
解题思路:首先可以维护每个位置向上的最大生长高度,然后按照每一行去枚举列,维护一个单调队列,使得高度递增,以及长度最优(在添加的那步进行控制)。对于每个新的长度,将比它高的直接忽略。
#include <stdio.h>#include <string.h>#include <algorithm>#include <stack>using namespace std;const int N = 1e3+5;typedef pair<int, int> pi;int n, m, v[N][N], ans[2*N];void init() {char str[N];memset(v, 0, sizeof(v));memset(ans, 0, sizeof(ans));scanf("%d%d", &n, &m);for (int i = 1; i <= n; i++) {scanf("%s", str+1);for (int j = 1; j <= m; j++) {if (str[j] == '#') v[i][j] = 0;else v[i][j] = v[i-1][j] + 1;}}}void solve () {for (int i = 1; i <= n; i++) {stack<pi> s;for (int j = 1; j <= m; j++) {int p = j;while (!s.empty() && s.top().first >= v[i][j]) {p = s.top().second;s.pop();}if (!v[i][j]) continue;if (s.empty() || v[i][j] - s.top().first > p - s.top().second) {ans[v[i][j] + j - p + 1]++;s.push(make_pair(v[i][j], p));} else ans[s.top().first + j - s.top().second + 1]++;}}for (int i = 1; i <= n + m; i++) {if (ans[i]) printf("%d x %d\n", ans[i], i * 2);}}int main () {int cas;scanf("%d", &cas);while (cas--) {init();solve();}return 0;}
1 0
- uva 12265 - Selling Land(dp)
- UVA 12265 Selling Land
- UVA-12265 Selling Land
- UVA 12265 Selling Land
- UVA - 12265 Selling Land 分析
- UVa OJ 12265 - Selling Land
- UVa 12265:Selling Land(单调栈)
- 12265 - Selling Land
- UVa 12265 Selling Land 解题报告(降维)
- 12265 - Selling Land(单调队列)
- SPOJ 8628 Selling Land
- uva12265 selling land
- UVALive 4950 Selling Land
- 【UVa12265】Selling Land 贩卖土地
- UVA 10074 Take the Land dp/暴力+剪枝
- UVa 516-Prime Land
- Codeforces 808E Selling Souvenirs【思维+Dp】
- UVa 10074 - Take the Land
- Spark 源码解析 ----RDD创建与本质
- (beginer) 凸包 UVA 1303 - Wall
- CRectTracker类的使用
- 详谈为何两台主机网络掩码不一致可能导致ping不通
- c#中event内幕(add与remove)
- uva 12265 - Selling Land(dp)
- 软件集成测试(IT)在项目中的实践和思考
- 【2013年,左边是苦,右边是甜】
- C++指针和引用
- 译文:C#中的弱事件(Weak Events in C#)
- UML中include和extend关系
- 麦当劳的盈利模式
- 在ENVI中对遥感图像拼接时遇到黑色条带的问题
- win7单击打开目录的设置方法