zoukankan      html  css  js  c++  java
  • uva 12265 贩卖土地

    题目大意

    有一个矩阵 有些点可以取有些不能

    求以每个点为右下角的子矩阵(里面点都可以取)的周长最大值

    最后统计出每个周长对应矩阵的个数

    思路:

    单调栈

    先预处理出每个点向上最多能延伸多长记为h(i,j)

    然后对于每行维护一个单调栈记录每行最远可以达到的左端点和该矩形的高

    该单调栈满足高单调递增

    每次加入一个元素时,判断新增加的高度是否比减去的长度多

    若是,就加入栈,反之不入栈

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstdlib>
     4 #include<cmath>
     5 #include<algorithm>
     6 #include<cstring>
     7 #include<queue>
     8 #include<vector>
     9 #define ll long long
    10 #define inf 2147483611
    11 #define MAXN 1010
    12 #define MOD
    13 using namespace std;
    14 inline int read()
    15 {
    16     int x=0,f=1;
    17     char ch;ch=getchar();
    18     while(!isdigit(ch)) {if(ch=='-') f=-1;ch=getchar();}
    19     while(isdigit(ch)) {x=x*10+ch-'0';ch=getchar();}
    20     return x*f;
    21 }
    22 int pos,top,T,n,m,ans[MAXN*2],h[MAXN][MAXN];
    23 char map[MAXN];
    24 struct data
    25 {
    26     int x,y;
    27 }s[MAXN];
    28 int main()
    29 {
    30     T=read();
    31     while(T--)
    32     {
    33         n=read(),m=read();
    34         memset(h,0,sizeof(h));
    35         memset(ans,0,sizeof(ans));
    36         for(int i=1;i<=n;i++)
    37         {
    38             scanf("%s",map+1);
    39             for(int j=1;j<=m;j++) 
    40                 if(map[j]=='.') h[i][j]=h[i-1][j]+1;
    41         }
    42         for(int i=1;i<=n;i++)
    43         {
    44             memset(s,0,sizeof(s));top=0;
    45             for(int j=1;j<=m;j++)
    46             {
    47                 pos=j;
    48                 while(top&&s[top].y>=h[i][j]) {pos=s[top].x;top--;}
    49                 if(!h[i][j]) continue;
    50                 if(!top||h[i][j]-s[top].y>pos-s[top].x) 
    51                 {
    52                     ans[h[i][j]+j-pos+1]++;
    53                     data tmp;tmp.x=pos,tmp.y=h[i][j];
    54                     s[++top]=tmp;
    55                 }
    56                 else ans[s[top].y+j-s[top].x+1]++;
    57             }
    58         }
    59         for(int i=1;i<=n+m;i++)
    60         {
    61             if(ans[i]) printf("%d x %d
    ",ans[i],i*2);
    62         }
    63     }
    64 }
    View Code
  • 相关阅读:
    QButton
    注入
    SpringBoot热重启配置
    centos7 安装 tomcat
    centos 安装jdk
    spring boot (6) AOP的使用
    spring boot (5) 自定义配置
    spring boot (4) 使用log4 打印日志
    SpringBoot (3)设置支持跨域请求
    spring boot (2) 配置swagger2核心配置 docket
  • 原文地址:https://www.cnblogs.com/yyc-jack-0920/p/7617067.html
Copyright © 2011-2022 走看看