uva12265 Selling Land
见紫书。
(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的更多相关文章
- UVa 12265 (单调栈) Selling Land
紫书上分析了很多很多,超详细,= ̄ω ̄= 每扫描一行可以计算一个height数组,表示从这块空地向上延伸多少块空地,而且这个数组可以逐行递推. 首先对于每一行来说维护一个单调栈,栈里放的是矩形的左上角 ...
- UVa 12265 - Selling Land
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- NOIP2018 - 暑期博客整理
暑假写的一些博客复习一遍.顺便再写一遍或者以现在的角度补充一点东西. 盛暑七月 初涉基环外向树dp&&bzoj1040: [ZJOI2008]骑士 比较经典的基环外向树dp.可以借鉴的 ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- POJ 1365 Prime Land(数论)
题目链接: 传送门 Prime Land Time Limit: 1000MS Memory Limit: 10000K Description Everybody in the Prime ...
- [2015hdu多校联赛补题]hdu5378 Leader in Tree Land
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5378 题意:给你一棵n个结点的有根树.因为是有根树,那么每个结点可以指定以它为根的子树(后面讨论的子树 ...
- UVALive 7261 Xiongnu's Land (扫描线)
Wei Qing (died 106 BC) was a military general of the Western Han dynasty whose campaigns against the ...
- hdu----(5050)Divided Land(二进制求最大公约数)
Divided Land Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tota ...
- 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 ...
随机推荐
- 默认action和ActionSupport
默认action: <action></action>中的name属性值与<default-action-ref></default-action-ref&g ...
- 【前端】CentOS 7 系列教程之五: 安装最新版 nginx 并转发 node 服务
转载请注明出处:http://www.cnblogs.com/shamoyuu/p/linux_5.html 进入/usr/local目录 cd /usr/local 下载最新版的ngxin压缩包 w ...
- Python网络爬虫之BeautifulSoup模块
一.介绍: Beautiful Soup 是一个可以从HTML或XML文件中提取数据的Python库.它能够通过你喜欢的转换器实现惯用的文档导航,查找,修改文档的方式.Beautiful Soup会帮 ...
- php大小写转换函数
1.将字符串转换成小写 strtolower(): 该函数将传入的字符串参数所有的字符都转换成小写,并以小定形式放回这个字 符串.例: <?php $str = "I want T ...
- ASP.NET Core 依赖注入(DI)
ASP.NET Core的底层设计支持和使用依赖注入.ASP.NET Core 应用程序可以利用内置的框架服务将服务注入到启动类的方法中,并且应用程序服务也可以配置注入.由ASP.NET Core 提 ...
- hihocoder 1582 : Territorial Dispute(凸包)
传送门 题意 略 分析 求一个凸包即可 1.所有点在凸包上且点数>3,令凸包上第1,3点为'A',其余点为'B' 2.部分点在凸包上,令凸包上点为'A',其余点为'B' 3.无可行情况 附代码 ...
- hdoj5813【构造】
2016 Multi-University Training Contest 7 05 真的真的好菜哇... 思路: 暴力. 我对那些到达目的地少的点做硬性规定就是去比他要到达目的地更少的点,这样一来 ...
- 51单片机 HC05蓝牙模块
一.注意事项 1.烧写程序时,要把蓝牙tx,rx信号线拔掉,对烧写程序有影响. 2.执行HC05集命令时,均以\r\n结尾.串口中断若选择“发送新行”时,不用添加\r\n.原理相同. 二.准备软硬件 ...
- mysql 分区后查询效率
准备工作: 蠕虫复制 文章表 增加数据到112万 语法:insert into tableNameA select * from tableNameB 未分区查询 54s 改变现有表 ...
- the little schemer 笔记(10.1)
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 China Mainla ...