题意

这片土地被分成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. 获取url参数,替换特殊字符

    function GetQueryString(name){ var reg = new RegExp("(^|&)"+ name +"=([^&]*)( ...

  2. 关于mybatis mapper.xml中的if判断

    场景: 页面上有搜索框进行调节查询,不同搜索框中的内容可以为空. 过程: 点击搜索,前端把参数传给后台,这是后台要把为空的参数过滤掉. 做法: 通常我们在dao层即mapper.xml中进行过滤判断操 ...

  3. Java读写文化总结

    Java读文件 package 天才白痴梦; import java.io.BufferedReader; import java.io.File; import java.io.FileInputS ...

  4. 卸载Linux自带的JDK

    Redhat Enterprise Linux中自带了jdk的旧版本,往往需要卸载,卸载步骤如下: 在终端输入:yum remove java 终端显示:Is this ok[y/N]: 输入y,按回 ...

  5. vue router使用query和params传参的使用

    传参是前端经常需要用的一个操作,很多场景都会需要用到上个页面的参数,本文将会详细介绍vue router 是如何进行传参的,以及一些小细节问题.有需要的朋友可以做一下参考,希望可以帮到大家. Vue ...

  6. C++复习3.C/C++常量的知识

    C/C++常量的知识 20130918 语言的实现隐含着使用着一些常量,如初始化全局变量静态变量,另外还有一些我们不曾感觉到的变量:函数地址(也就是函数名称), 静态数组的名字,字符串常亮的地址.常量 ...

  7. 使用Eclipse EE(汉化版) 创建一个JavaWeb工程

    第一步:打开eclipse ee,单击“文件”-->单击“新建”-->单击“动态Web项目”. 若没找到“动态Web项目”,单击“其他” -->在弹出的窗口中打开“Web”下拉菜单 ...

  8. Javascript-- jQuery动画篇(2)

    动画效果 前面的 hide/show,slide in/out 其实也具有动画效果,本篇介绍使用 animate()实现自定义动画效果. 基本语法如下: $(selector).animate({pa ...

  9. ElasticSearchRepository和ElasticSearchTemplate的使用

    Spring-data-elasticsearch是Spring提供的操作ElasticSearch的数据层,封装了大量的基础操作,通过它可以很方便的操作ElasticSearch的数据. 版本说明 ...

  10. 开启 Android WebView 的安全浏览模式

    Hybrid App(混合式开发)已经是每一个商业应用都会使用的开发手段.其最大的优势就是将一些可动态更新的内容页面使用 H5 开发,然后借用移动端原生系统提供的 WebView 控件加载进来.这种方 ...