2 条题解

  • 3
    @ 2021-8-7 20:58:04

    C++ :

    
    #include<bits/stdc++.h>
    #define IO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
    using namespace std;
    inline int read()
    {
        char ch=getchar();
        int f=1,x=0;
        while(!(ch>='0'&&ch<='9')){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();}
        return x*f;
    }
    const int maxn=1e3+5;
    struct rectangle{int h,l;};
    int n,m,t[maxn][maxn];
    char c;
    int getmaxv(int size,int buffer[])
    {
        stack<rectangle>S;
        int maxv=0;
        buffer[size]=0;
        for(int i=0;i<=size;i++)
        {
            rectangle rect;
            rect.h=buffer[i];
            rect.l=i;
            if(S.empty())S.push(rect);
            else
            {
                if(S.top().h<rect.h)S.push(rect);
                else
                {
                    int target=i;
                    while(!S.empty()&&S.top().h>=rect.h)
                    {
                        rectangle pre=S.top();
                        S.pop();
                        int area=pre.h*(i-pre.l);
                        maxv=max(maxv,area);
                        target=pre.l;
                    }
                    rect.l=target;
                    S.push(rect);
                }
            }
        }
        return 3*maxv;
    }
    int main()
    {
        IO;
        cin>>n>>m;
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<m;j++)
            {
                cin>>c;
                c=='R'?t[i][j]=0:i==0?t[i][j]=1:t[i][j]=t[i-1][j]+1;
            }
        }
        int maxv=0;
        for(int i=0;i<n;i++)maxv=max(maxv,getmaxv(m,t[i]));
        printf("%d\n",maxv);
        return 0;
    }
    
    • 1
      @ 2023-5-26 18:03:23

      思路:

      这道题就是在直方图中的矩形里再多一个枚举
      行就行了,下面是代码
      

      AC代码:

      #include<iostream>
      #include<stack>
      #include<string.h>
      #define IO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
      #define int long long
      using namespace std;
      stack<int> st;
      int h[1005][1005],n,to,l[1005],r[1005],res,m;
      int get(int index){
          int ans;
          while(!st.empty()) st.pop();
          h[0][index]=-1;
          st.push(0);
          for(int i=1;i<=n;i++){
              while(!st.empty()&&h[i][index]<=h[st.top()][index]) st.pop();
              l[i]=st.top();
              st.push(i);
          }
          while(!st.empty()) st.pop();
          h[n+1][index]=-1;
          st.push(n+1);
          for(int i=n;i>=1;i--){
              while(!st.empty()&&h[i][index]<=h[st.top()][index]) st.pop();
              r[i]=st.top();
              st.push(i);
          }
          ans=0;
          for(int i=1;i<=n;i++){
              ans=max(ans,(r[i]-l[i]-1)*h[i][index]);
          }
          return ans;
      }
      signed main(){
          IO;
          cin>>m>>n;
          char x;
          for(int i=1;i<=m;i++){
              for(int j=1;j<=n;j++){
                  cin>>x;
                  if(x=='F') h[j][i]=h[j][i-1]+1;
                  else  h[j][i]=0;
              }
          }
          int maxx =-1;
          for(int i=1;i<=m;i++)
              maxx=max(maxx,get(i));
          cout<<maxx*3;
          return 0;
      }
      
      
      
      • 1

      信息

      ID
      63
      时间
      1000ms
      内存
      128MiB
      难度
      1
      标签
      递交数
      72
      已通过
      50
      上传者