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 ...
随机推荐
- MultiAutoCompleteTextView
Activity_mian.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android&qu ...
- 【旧文章搬运】无Device的驱动如何通信
原文发表于百度空间,2009-07-14========================================================================== 标准的驱动 ...
- 6-5 Haar特征2
在遍历的过程中还需要考虑到一个步长的问题.这个模板一次滑动10个像素,那么总共就需要滑动9次.再加上最开始的第0次,合计在水平方向上和竖直方向上分别都有10个这样的模板,总共也就是100个模板.要计算 ...
- Linux中的gdb调试方法总结
- ORACLE PL/SQL 实例精解之第二章 通用编程语言基础
通用编程语言基础 2.1PL/SQL编程基础 1. 字符类型:支持四中类型字符:字母,数字,符号和空格,组合一个或多个字符就会创建一个词汇单元 2. 词汇单元 a.标识符必须以字符开头 b.保留字是p ...
- (水题)洛谷 - P1014 - Cantor表
https://www.luogu.org/problemnew/show/P1014 很显然同一对角线的和是相等的.我们求出前缀和然后二分. 最后注意奇偶的顺序是相反的. #include<b ...
- POJ2576【背包】
题意: 每个人必须在一个团队或其他; 人对两支球队的数量不得超过1不同; 人们对各队的总重量应尽可能接近相等越好. 思路: 那么我求一个能接近最接近总和一半的值. 每个人的值就是物品,每个物品有且只有 ...
- 关于 <meta name="viewport" content="width=device-width, initial-scale=1.0">的解释
对于移动开发来讲,我还不太熟悉.今天在github上荡了一个系统源码,进行分析.发现其中有这样一段话: <meta name="viewport" content=" ...
- bzoj 1874: [BeiJing2009 WinterCamp]取石子游戏【博弈论】
先预处理出来sg值,然后先手必败状态就是sg[a[i]]的xor和为0(nim) 如果xor和不为0,那么一定有办法通过一步让xor和为0,具体就是选一个最大的sg[a[i]],把它去成其他sg值的x ...
- bug日志-天坑,Spring Security的登陆报错:An internal error occurred while trying to authenticate the user.
在学习Spring Security的时候,我的编辑器给我报错:An internal error occurred while trying to authenticate the user. 明明 ...