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 ...
随机推荐
- python-----实现print不换行
python中print输出是默认换行的,那如何我们不想换行,且需要用多个print函数输出时,就需要改变print默认换行的属性: 例: print('Hello') print('!') 输出结果 ...
- Code:NFine框架
ylbtech-Code:NFine框架 1.返回顶部 1. 2. 2.返回顶部 3.返回顶部 4.返回顶部 5.返回顶部 6.返回顶部 作者:ylbtech出 ...
- 【199】ArcGIS 添加自定义工具到工具箱
点击工具栏最右边的三角块,弹出菜单,点击“Customize”. 切换到“Command”,在搜索框中输入“idw”查找相应工具,然后将工具通过鼠标左键拖拽到工具栏中. 在工具上右键修改工具的显示图片 ...
- CF 8D two friends
独立想的好开心呀(然而是一道水题). 可以看出这道题的答案是满足单调性的,然后可以考虑二分. 对于当前二分出的mid值,我们考虑这个过程. 假设他们能共同走到shop然后共同会home $$Ans = ...
- A. Vanya and Table
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- iOS---UICollectionView Class Reference---UICollectionView 类参考文档
UICollectionView 类: Inherits from UIScrollView : UIView : UIResponder : NSObject Conforms to NSCodin ...
- 003--linux用户权限常用命令
一.useradd命令选项 –u:指定用户的UID useradd –u 1024 mu #指定mu的UID为1024 –g:指定用户所属的群组 useradd –g jac ...
- bzoj 4407: 于神之怒加强版【莫比乌斯反演+线性筛】
看着就像反演,所以先推式子(默认n<m): \[ \sum_{d=1}^{n}d^k\sum_{i=1}^n\sum_{j=1}^m[gcd(i,j)==d] \] \[ =\sum_{d=1} ...
- C#程序结构与基本语法
C# 程序结构 Hello World 实例 一个 C# 程序主要包括以下部分: 命名空间声明(Namespace declaration) 一个 class Class 方法 Class 属性 一个 ...
- Beta版本冲刺第二天!
该作业所属课程:https://edu.cnblogs.com/campus/xnsy/SoftwareEngineeringClass2 作业地址:https://edu.cnblogs.com/c ...