见紫书。
(c,h)的更新策略://前面的高度为0了,直接插入
因为ans==-c+h,c大,h还小,那么肯定不是最优左上角,更新新加入列的列
//新的一列高度最小,就删掉了其他的,只留这个高度
从上到下,从左到右扫描一遍

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std; const int maxn = ; char s[maxn][maxn];
int height[maxn], ans[maxn*]; struct Rect {
int c, h;
Rect(int c=, int h=):c(c),h(h){}
}; Rect rect[maxn]; // stack int main() {
int n, m, T;
scanf("%d", &T);
while(T--) {
scanf("%d%d", &n, &m);
for(int i = ; i < n; i ++) scanf("%s", s[i]); memset(height, , sizeof(height));
memset(ans, , sizeof(ans));
for(int i = ; i < n; i ++) {
int top = -;
for(int j = ; j < m; j ++) {
if(s[i][j] == '#') {
height[j] = ;
top = -; // clear stack
} else {
height[j]++;
Rect r(j, height[j]);
if(top < ) rect[++top] = r; //前面的高度为0了
else {
while(top >= && r.h <= rect[top].h) r.c = rect[top--].c; //因为-c+h,c大,h还小,那么肯定不是最优左上角
if(top < || r.h - r.c > rect[top].h - rect[top].c) rect[++top] = r;//新的一列高度最小,就删掉了其他的,只留这个高度
}
ans[j-rect[top].c+rect[top].h+]++;
}
}
}
for(int i = ; i <= n + m; i++)
if(ans[i]) printf("%d x %d\n", ans[i], i*);
}
return ;
}

uva12265 Selling Land的更多相关文章

  1. UVa 12265 (单调栈) Selling Land

    紫书上分析了很多很多,超详细,= ̄ω ̄= 每扫描一行可以计算一个height数组,表示从这块空地向上延伸多少块空地,而且这个数组可以逐行递推. 首先对于每一行来说维护一个单调栈,栈里放的是矩形的左上角 ...

  2. UVa 12265 - Selling Land

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  3. NOIP2018 - 暑期博客整理

    暑假写的一些博客复习一遍.顺便再写一遍或者以现在的角度补充一点东西. 盛暑七月 初涉基环外向树dp&&bzoj1040: [ZJOI2008]骑士 比较经典的基环外向树dp.可以借鉴的 ...

  4. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  5. POJ 1365 Prime Land(数论)

    题目链接: 传送门 Prime Land Time Limit: 1000MS     Memory Limit: 10000K Description Everybody in the Prime ...

  6. [2015hdu多校联赛补题]hdu5378 Leader in Tree Land

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5378 题意:给你一棵n个结点的有根树.因为是有根树,那么每个结点可以指定以它为根的子树(后面讨论的子树 ...

  7. UVALive 7261 Xiongnu's Land (扫描线)

    Wei Qing (died 106 BC) was a military general of the Western Han dynasty whose campaigns against the ...

  8. hdu----(5050)Divided Land(二进制求最大公约数)

    Divided Land Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tota ...

  9. hdu-----(1507)Uncle Tom's Inherited Land*(二分匹配)

    Uncle Tom's Inherited Land* Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

随机推荐

  1. Python-Django使用MemcachedCache缓存

    最近工作中使用到缓存,简单记录之... 关于django的几种缓存方式,就不在做介绍了,网上一搜一大把:1.8.2官方文档, Django 缓存,Python菜鸟之路:django缓存 学习了之后,选 ...

  2. label标签的可访问性

    与表单元素关联的方法(IE6下label标签包裹控件的方法是不顶用的): 1 使用for和id关联控件 <p><label for="test">标签< ...

  3. 1004 n^n的末位数字

    题目来源: Author Ignatius.L (Hdu 1061) 基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题   给出一个整数N,输出N^N(N的N次方)的十 ...

  4. B. Spider Man

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  5. 任务47:Identity MVC:ReturnUrl实现

    任务47:Identity MVC:ReturnUrl实现 在最上面加一个私有的方法 登陆也加上returnUrl Login的post方法.加入returnUrl的参数 登陆界面也需要加上 asp- ...

  6. typeof操作符返回一个字符串,表示未经计算的操作数的类型。

    typeof操作符返回一个字符串,表示未经计算的操作数的类型.   语法 typeof运算符后跟操作数: typeof operand or typeof (operand) 参数 operand 是 ...

  7. STS和Eclipse安装Lombok插件

    参考:https://www.cnblogs.com/caozx/p/9510354.html 参考:https://blog.csdn.net/wutian90/article/details/87 ...

  8. bzoj 1478: Sgu282 Isomorphism && 1815: [Shoi2006]color 有色图【dfs+polya定理】

    参考 https://wenku.baidu.com/view/fee9e9b9bceb19e8b8f6ba7a.html?from=search### 的最后一道例题 首先无向完全图是个若干点的置换 ...

  9. bzoj1257[CQOI2007]余数之和(除法分块)

    1257: [CQOI2007]余数之和 Time Limit: 5 Sec  Memory Limit: 128 MBSubmit: 6117  Solved: 2949[Submit][Statu ...

  10. LuoguP2115 [USACO14MAR]破坏Sabotage【二分答案】By cellur925

    本来是想找一道生成树的题做的...结果被洛咕的标签骗到了这题...结果是二分答案与生成树一点mao关系都没有.... 题目大意:给你一个序列,请你删去某一个$l~r$区间的值($2<=i< ...