题意

这片土地被分成NM个格子,每个格子里写着'R'或者'F',R代表这块土地被赐予了rainbow,F代表这块土地被赐予了freda。

现在freda要在这里卖萌。。。它要找一块矩形土地,要求这片土地都标着'F'并且面积最大。

但是rainbow和freda的OI水平都弱爆了,找不出这块土地,而蓝兔也想看freda卖萌(她显然是不会编程的……),所以它们决定,如果你找到的土地面积为S,它们每人给你3
S两银子。

1<=N,M<=1000

分析

最大01子矩阵,单调栈解决。我还是第一次看到正规写法的单调栈,原来还要记录长度。

比较通用的技巧是使用0来清空栈已达到统计完全的目的。

时间复杂度\(O(NM)\)

代码

话说没人给3S银子不就9S了吗?

#include<bits/stdc++.h>
#define rg register
#define il inline
#define co const
template<class T>il T read(){
rg T data=0,w=1;
rg char ch=getchar();
while(!isdigit(ch)){
if(ch=='-') w=-1;
ch=getchar();
}
while(isdigit(ch))
data=data*10+ch-'0',ch=getchar();
return data*w;
}
template<class T>il T read(rg T&x){
return x=read<T>();
}
typedef long long ll; co int N=1e3+1;
int a[N][N],b[N];
int s[N],w[N],p;
int main(){
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
int n=read<int>(),m=read<int>();
char buf[2];
for(int i=1;i<=n;++i)
for(int j=1;j<=m;++j){
scanf("%s",buf);
a[i][j]=buf[0]=='F';
}
int ans=0;
for(int i=1;i<=n;++i){
for(int j=1;j<=m;++j)
b[j]=a[i][j]?b[j]+1:0;
p=0;
for(int j=1;j<=m+1;++j){
if(b[j]>s[p]) s[++p]=b[j],w[p]=1;
else{
int width=0;
while(s[p]>b[j]){
width+=w[p];
ans=std::max(ans,width*s[p]);
--p;
}
s[++p]=b[j],w[p]=width+1;
}
}
}
printf("%d\n",3*ans);
return 0;
}

CH1803 City Game的更多相关文章

  1. BZOJ 2001: [Hnoi2010]City 城市建设

    2001: [Hnoi2010]City 城市建设 Time Limit: 20 Sec  Memory Limit: 162 MBSubmit: 1132  Solved: 555[Submit][ ...

  2. History lives on in this distinguished Polish city II 2017/1/5

    原文 Some fresh air After your time underground,you can return to ground level or maybe even a little ...

  3. History lives on in this distinguished Polish city 2017/1/4

    原文 History lives on in this distinguished Polish city Though it may be ancient. KraKow, Poland, is a ...

  4. #1094 : Lost in the City

    时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Little Hi gets lost in the city. He does not know where he is ...

  5. GeoIP Legacy City数据库安装说明

    Here is a brief outline of the steps needed to install GeoIP Legacy City on Linux/Unix. The installa ...

  6. [POJ3277]City Horizon

    [POJ3277]City Horizon 试题描述 Farmer John has taken his cows on a trip to the city! As the sun sets, th ...

  7. 2015年第8本(英文第7本):the city of ember 微光城市

    书名:the City of Ember(中文名:微光城市) 作者:Jeanne DuPrau 单词数:6.2万 不重复单词数:未知 首万词不重复单词数:未知 蓝思值:未知 阅读时间:2015年4月2 ...

  8. 离散化+线段树 POJ 3277 City Horizon

    POJ 3277 City Horizon Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 18466 Accepted: 507 ...

  9. HDU 1505 City Game (hdu1506 dp二维加强版)

    F - City Game Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submi ...

随机推荐

  1. c中%

    %u 十进制无符号整数 %f 浮点数 %s 字符串 %c 单个字符 %p 指针的值 %e 指数形式的浮点数 %x, %X 无符号以十六进制表示的整数 %0 无符号以八进制表示的整数 %g 自动选择合适 ...

  2. 网页上播放音频、视频Mp3,Mp4

    昨天在处理网页上播放音频mp3,视频mp4上用了一天的时间来比较各种方案,最终还是选择了HTML5的 标签,谷歌浏览器.IE浏览器对标签的支持都很好,火狐上需要安装quicktime插件,效果比较差. ...

  3. 【转】VIM 中设置Tab

    灵活操作 Vim 中的 Tabsgaleki post @ 2007年11月16日 05:07PM in Vim Tips with tags: vim tabs Vim 支持 Tabs,也就是标签页 ...

  4. Ansible 小手册系列 二十(经常遇到的问题)

    (1). 怎么为任务设置环境变量? - name: set environment shell: echo $PATH $SOME >> /tmp/a.txt environment: P ...

  5. 初识async函数

    为什么会出现async函数 首先从大的方面来说,出现async函数时为了解决JS编程中的异步操作,再往具体说就是为了对以往异步编程方法的一种改进,也有人说仅仅只是Generator 函数的语法糖,这个 ...

  6. Docker的大坑小洼(二)

    再谈<Docker的大坑小洼> 今天闲暇看了一下宏亮同学写的一篇<Docker的大坑小洼>,非常受启发.因为Docker的文章真的很多了,但大家如果只是玩一玩,有很多坑是不会碰 ...

  7. C#学习历程(四)[实际问题]

    >>无法直接启动带有”类库输出类型”的项目 在编辑界面的右侧会出现[解决方案资源管理器],里面显示我们的程序项目和所有代码文件. 右键点击项目,在右键菜单中选择[属性] 一般导致该问题都是 ...

  8. 深入理解java泛型

    一. 什么是泛型? 泛 型(Generic type 或者 generics)是对 简单的理解,就是对类型的参数化,比如我们定义一个类属性或者实例属性时,往往要指定具体的类型,如Integer.Per ...

  9. office在繁体系统下 导入导出 功能灰显的解决方法

    当在win7系统使用繁体中文版的office时,或系统是繁体版时,可能会导致office的导入导出功能无法使用 解决方法: 控制面板--区域和语言--格式--中文简体

  10. webpack 事件触发 按需加载

    比较易懂, 方法简单 var util_sync = require('./util-sync.js') alert(util_sync.data) document.getElementById(& ...