题意

这片土地被分成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了吗?

  1. #include<bits/stdc++.h>
  2. #define rg register
  3. #define il inline
  4. #define co const
  5. template<class T>il T read(){
  6. rg T data=0,w=1;
  7. rg char ch=getchar();
  8. while(!isdigit(ch)){
  9. if(ch=='-') w=-1;
  10. ch=getchar();
  11. }
  12. while(isdigit(ch))
  13. data=data*10+ch-'0',ch=getchar();
  14. return data*w;
  15. }
  16. template<class T>il T read(rg T&x){
  17. return x=read<T>();
  18. }
  19. typedef long long ll;
  20. co int N=1e3+1;
  21. int a[N][N],b[N];
  22. int s[N],w[N],p;
  23. int main(){
  24. // freopen(".in","r",stdin);
  25. // freopen(".out","w",stdout);
  26. int n=read<int>(),m=read<int>();
  27. char buf[2];
  28. for(int i=1;i<=n;++i)
  29. for(int j=1;j<=m;++j){
  30. scanf("%s",buf);
  31. a[i][j]=buf[0]=='F';
  32. }
  33. int ans=0;
  34. for(int i=1;i<=n;++i){
  35. for(int j=1;j<=m;++j)
  36. b[j]=a[i][j]?b[j]+1:0;
  37. p=0;
  38. for(int j=1;j<=m+1;++j){
  39. if(b[j]>s[p]) s[++p]=b[j],w[p]=1;
  40. else{
  41. int width=0;
  42. while(s[p]>b[j]){
  43. width+=w[p];
  44. ans=std::max(ans,width*s[p]);
  45. --p;
  46. }
  47. s[++p]=b[j],w[p]=width+1;
  48. }
  49. }
  50. }
  51. printf("%d\n",3*ans);
  52. return 0;
  53. }

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. meta标签中的http-equiv属性使用介绍

      meta是html语言head区的一个辅助性标签.也许你认为这些代码可有可无.其实如果你能够用好meta标签,会给你带来意想不到的效果,meta 标签的作用有:搜索引擎优化(SEO),定义页面使用 ...

  2. js打乱数组的实战应用

    文章首发于: https://www.xiabingbao.com/post/javascript/js-random-array.html 在js中,能把数组随机打乱的方法有很多,每个方法都有自己的 ...

  3. 22.线程池之ScheduledThreadPoolExecutor

    1. ScheduledThreadPoolExecutor简介 ScheduledThreadPoolExecutor可以用来在给定延时后执行异步任务或者周期性执行任务,相对于任务调度的Timer来 ...

  4. 1-15-2-RAID10 企业级RAID磁盘阵列的搭建(RAID1、RAID5、RAID10)

    RAID10的搭建: 有两种方法, 第一种:直接使用四块磁盘,创建级别为10的磁盘阵列 第二种:使用四块磁盘先创建两个RAID1,然后在用RAID1创建RAID0 第一步:添加五个磁盘到虚拟机 开机后 ...

  5. 第九天 1-8 实战:安装nginx服务器

    简介:使用nginx源码包,安装nginx服务器,并对其进行配置后,测试其成果.模仿百度主页! 第一步:检查依赖关系[root@xiaogan ~]# rpm -q zlib-devel pcre-d ...

  6. IOS-CocoaPods的详细安装与使用

    1.为什么需要CocoaPods 在进行iOS开发的时候,总免不了使用第三方的开源库,比如SBJson.AFNetworking.Reachability等等.使用这些库的时候通常需要: 下载开源库的 ...

  7. css去掉input记住密码的黄色

    input:-webkit-autofill,input:-webkit-autofill:hover,input:-webkit-autofill:focus,input:-webkit-autof ...

  8. ZOJ 2283 Challenge of Wisdom 数论,Dilworth Theorem,求最长反链 难度:2

    Challenge of Wisdom Time Limit: 2 Seconds      Memory Limit: 32768 KB Background "Then, I want ...

  9. H5页面下拉加载更多(实用版)

    近期在做一个H5网站,需要下拉加载更多产品列表的功能.百度搜索了好久,什么说法都有,什么插件都有.   醉了.基本上每一个能直接拿来用的. 最后发现: 1.dropload.js 插件  还可以,但是 ...

  10. LeetCode OJ:Ugly Number II(丑数II)

    Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime factors ...